Jump to content

Performing octave transpose in MB64


Recommended Posts

Is it possible to insert a short routine at MIDI_EVNT_Send_9x to add 0x0C or 0x00 to MIDI_EVNT1 (this would be the note number) from a user register, before the Note On gets sent? Is it then possible to use a meta event as a hook to store either 0x00 or 0x0c in that user register? Would this achieve an octave toggle? What register should be used?

excert from midi_evnt.inc

;; sending three bytes:

MIDI_EVNT_Send_8x ; Note Off.

    rgoto        MIDI_EVNT_Send_Bx

MIDI_EVNT_Send_9x ; Note On

     ;; add a routine here

MIDI_EVNT_Send_Ax ; Aftertouch

MIDI_EVNT_Send_Bx ; Controller

movff MIDI_EVNT0, WREG

call MIOS_MIDI_TxBufferPut

movff MIDI_EVNT1, WREG

andlw 0x7f

call MIOS_MIDI_TxBufferPut

movff MIDI_EVNT_VALUE, WREG

andlw 0x7f

call MIOS_MIDI_TxBufferPut

rgoto MIDI_EVNT_Send_End

If I am barking up the wrong tree, is there a better way to approach this?

thanks

Keith

Link to comment
Share on other sites

Don't you want it to work for note off's? ;)

Define a new variable for this, and set it's value as 0x0c in a meta event like you said, then around line 56 of midi_evnt.inc:

	;; sending three bytes:	
MIDI_EVNT_Send_8x	; Note Off
MIDI_EVNT_Send_9x	; Note On

;; Add your variable to evnt1 here

MIDI_EVNT_Send_Ax	; Aftertouch
MIDI_EVNT_Send_Bx	; Controller
	movff	MIDI_EVNT0, WREG
	call	MIOS_MIDI_TxBufferPut
	movff	MIDI_EVNT1, WREG
	andlw	0x7f
	call	MIOS_MIDI_TxBufferPut
	movff	MIDI_EVNT_VALUE, WREG
	andlw	0x7f
	call	MIOS_MIDI_TxBufferPut
	rgoto	MIDI_EVNT_Send_End

Link to comment
Share on other sites

app_defines.h is the go, you could put it at the bottom:


CSMD_POTBASE	EQU	0x299	;;holds POT# of top left pot in zone

;; ==========================================================================

NOTE_SHIFT	EQU	0x300	;;holds value for note number shift

This looks to be free also, and might be a better place:
;; used by drums.inc
DRUMS_STATE_BEGIN	EQU	0x068	; for 8 drum triggers
DRUMS_STATE_END		EQU	0x06f
DRUMS_MAX_VALUE_BEGIN	EQU	0x060	; for 8 drum triggers
DRUMS_MAX_VALUE_END	EQU	0x067
DRUMS_CTR		EQU	0x068	; used as loop counter


;; used by Bassman's note shifting code
NOTE_SHIFT	EQU	0x069	;;holds value for note number shift


;; ==========================================================================

Link to comment
Share on other sites

Well this is finally working. I got my mb64 to do transpose.

Here's my extra code to use META_EVENT_8 to perform a note shift or transpose.

When you assign a button to a meta event, in the Edit Events, first it's midi channel 1, the first hex number will be 08 (meta function #8) and the second hex number will be the number of half steps to transpose up (an octave will be 12 notes 0C hex). Lastly set the button mode to T (Toggle), unless you want to use 2 buttons for up and down, then O for OnOnly. In theory you can go up almost 10 octaves, yikes, at the touch of a button.

Hope it's useful for anyone.

Oh, one thing, I haven't trapped the possiblility of transposing whilst another button is held down, you'll get notes stuck on.

Insert into app_defines.h after line 196 DRUMS_CTR

;; used by Bassman's note shifting code
NOTE_SHIFT	EQU	0x69	;;holds value for note number shift
Insert into midi_event.inc after line 71 MIDI_EVNT_Send_9x
	;; pickup NOTE_SHIFT value and add to  current note number
	movf	NOTE_SHIFT, W			;; get note shift value
	addwf	MIDI_EVNT1, W 	
	movwf	MIDI_EVNT1	
so the section will look like;
	;; sending three bytes:	
MIDI_EVNT_Send_8x	; Note Off
MIDI_EVNT_Send_9x	; Note On
	;; pickup NOTE_SHIFT value and add to  current note number
	movf	NOTE_SHIFT, W			;; get note shift value
	addwf	MIDI_EVNT1, W 			;; add NOTE_SHIFT to MIDI_EVNT1 
	movwf	MIDI_EVNT1
MIDI_EVNT_Send_Ax	; Aftertouch
MIDI_EVNT_Send_Bx	; Controller
	movff	MIDI_EVNT0, WREG
	call	MIOS_MIDI_TxBufferPut
	movff	MIDI_EVNT1, WREG
	andlw	0x7f
	call	MIOS_MIDI_TxBufferPut
	movff	MIDI_EVNT_VALUE, WREG
	andlw	0x7f
	call	MIOS_MIDI_TxBufferPut
	rgoto	MIDI_EVNT_Send_End
This will only affect notes. But you could adapt it for other events, like move all your program changes up by 16 or 32 etc. In this case use similar 3 extra lines but put it after MIDI_EVNT_Send_Cx ; Program Change, just change the 2 references to MIDI_EVNT1 to MIDI_EVNT_VALUE. Lastly Insert into mb64_meta.inc after line 184 MB64_META_Handler_08;
	movff	MIDI_EVNT_VALUE, NOTE_SHIFT ;; Save shift amount in  NOTE_SHIFT
	return	 				;; exit
So it will look like this;
	;; a trick: all labels are pointing to the same routine

	;; Currently mb64_meta events are all F0, so midi channel 1
	;; Use the first hex number in Event Edit - Meta to determine which Meta handler # to jump to.
	;; Use the second hex number in Event Edit - Meta to determine number of notes to transpose
MB64_META_Handler_08 ;; Perform Note shift
	;; BANKED access not required - see mb64_meta.inc
	movff	MIDI_EVNT_VALUE, NOTE_SHIFT ;; Save shift amount in  NOTE_SHIFT
	return	 				;; exit
MB64_META_Handler_09
MB64_META_Handler_0A
MB64_META_Handler_0B
MB64_META_Handler_0C
MB64_META_Handler_0D
MB64_META_Handler_0E
MB64_META_Handler_0F

Many thanks to stryd_one, who helped me figure it out.

bassman

Link to comment
Share on other sites

There's no need to worry about this because the original code for sending 3 bytes already deals with this.

;; sending three bytes:

MIDI_EVNT_Send_8x ; Note Off

MIDI_EVNT_Send_9x ; Note On

MIDI_EVNT_Send_Ax ; Aftertouch

MIDI_EVNT_Send_Bx ; Controller

movff MIDI_EVNT0, WREG

call MIOS_MIDI_TxBufferPut

movff MIDI_EVNT1, WREG

andlw 0x7f ;; oveflow to above 0x7f dealt with here!

call MIOS_MIDI_TxBufferPut

movff MIDI_EVNT_VALUE, WREG

andlw 0x7f

call MIOS_MIDI_TxBufferPut

rgoto MIDI_EVNT_Send_End

but it was something I thought of, thanks, TK has already made sure nothing like that can upset things.

Anyway, I thought it best used with the button in Toggle mode, that way it transforms, then returns to normal.

bassman

Link to comment
Share on other sites

There's no need to worry about this because the original code for sending 3 bytes already deals with this.

...

true, as long as you don't mind very high notes becoming very low notes,

or if transposing down, very low notes becoming very high notes

Link to comment
Share on other sites

Hi bugfight,

Actually that can't happen. You can only implement this with Meta Evnt #8, whatever number you enter as the second Hex number in 'Edit Event' is the amount it will transpose up. It doesn't keep adding, no matter what mode you choose for the button. I suppose you could put a transpose of 127 (h7f), which would cause it to wrap around to 0, but why would anyone do that?

Anyway, I'm just trying to post things that might be useful to someone.

bassman

Link to comment
Share on other sites

Anyway, I'm just trying to post things that might be useful to someone.

It's totally useful and appreciated... But it makes sense to discuss such things for the optimal result, right? Bugfight and I spend hours upon hours discussing our methods, finding flaws and improvements in each others work.... we don't get offended by each other.... No need to be all passive-defensive :)

Link to comment
Share on other sites

To all,

Hey sorry to give the impression I was offended, not at all, I am grateful to everyone for their help.

I don't have anyone to discuss things with, except here, I thought that's what I was doing. Anyway nuff said!

Right now I am trying to figure out how to allow someone to press a button that sends a note on, and do the transpose whilst holding the note.

At the moment, the note gets left on, as the MIDI_EVNT1 gets added too, before note off (or rather note on, zero velocity). It might be easy enough to account for one note, but there could be a while chord.

Any ideas here?

Same would apply to Prog change. It might be usefull to shift a whole group of buttons up/down by 8 or 16. But if the transpose happened whilst a button was held down, it could get messy.

bassman

Link to comment
Share on other sites

OK back again (for now)....

What you're talking about doing now, is really a totally different kettle of fish to what you started talking about.

Initially, you wanted to configure an offset before sending an event.

Now, you will have to keep a queue of the events which are currently 'active', and then stop them all, apply the shift, and start them again. Really, it's a totally different thing, and maybe even better suited to a completely different application, as it will require significant mods to MB64's note sending functions.

Link to comment
Share on other sites

Yes, you're right, the more I thought about it, and looked at the code, the more complex it became.

In principal, I think the simple alterations I made were fine for the application, it is quite useful as a simple Meta Event, the user can program the transposition. With minor mods other Meta events can be used to shift Prg Changes or a particular controller etc. All useful to perhaps cut down on the amount of hardware needed, or to expand the use of current hardware used.

I'm trying to take it into the musical instrument sphere, which is not the purpose of the midibox64.

I'm happy to have achieved my little mod, I can do so much more with remote control using the transpose, to shift up/down a set of functions.

However, regarding your point.

you will have to keep a queue of the events which are currently 'active', and then stop them all, apply the shift, and start them again

Surely all I have to do is search the DIN registers, and that routine is already there somewhere. If I don't fine any zeros I can apply the shift, if there are zeros, wait until they're all set before applying the shift.

Wouldn't that work? I don't need to know what events are 'active', only if there are any?

bassman

Link to comment
Share on other sites

Aren't these the button events? Around line 285 in app_defines.h?

	;; button events, byte 0
MB64_BUTTON_EVNT0_00	EQU	0x200
	;; ...
MB64_BUTTON_EVNT0_3F	EQU	0x23f

	;; button events, byte 1
MB64_BUTTON_EVNT1_00	EQU	0x240
	;; ...
MB64_BUTTON_EVNT1_3F	EQU	0x27f

	;; button values (packed)
MB64_BUTTON_VALUES_SR0	EQU	0x280
	;; ...
MB64_BUTTON_VALUES_SR7	EQU	0x287

	;; midi button values (packed)
MB64_MBUTTON_VALUES_SR0	EQU	0x288
	;; ...
MB64_MBUTTON_VALUES_SR7	EQU	0x28f

Maybe I'm wrong, but this looks like the place.

bassman

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...