Jump to content

midi transpose code


technobreath
 Share

Recommended Posts

Yo, it's been a while since I was wondering what subforum to put a thread in, but this might be the best place for it.

 

I'm planning a "simple" box, 4 midi i/o - a prosessor - that simply transposes the incomming midinotes on a midi input. Either globally over all 4 midi ports or one by one.

 

I'm no coder, but as far as I understand I can use the LPC stuff I have laying around on my workbench (for ages now) for this. My question is really nothing more than:

 

Where do I go looking to find code examples relevant to what the box is supposed to do?

 

If the box is small in size, I'll have some select buttons, a LCD and an encoder on it. If it turns out it has to be bigger, I'll include buttons for selecting a tuning directly (that will be -12 to +12 semitones) instead of having to turn the encoder for each step, tho this is also a fast solution. Some LEDs will go with the buttons too for status indication besides the info from the LCD.

 

Anyway, this is a rather simple and boring project for being a midibox, but feel free to give me ideas :P hehe.

Link to comment
Share on other sites

Hola TB :-)

 

Maybe look into the MBSEQ v4 code - i find it is very readable and contains "on the fly" transposing.

And then dig into some of the MIOS32 coding examples, this should get you going regarding MIDI input + output and switch control :-)

 

Many greets from cold south-of-munich :)

Peter

Link to comment
Share on other sites

Yo, look no further, you´ll find the live transpose code in

seq_core.c within function SEQ_CORE_Transpose(...)

 

In the end it is as easy as adding the given number of halftones (inc_semi) and octaves (inc_oct) to the incoming note:

 

 // apply transpose octave/semitones parameter
  if( inc_oct ) {
    note += 12 * inc_oct;
    if( inc_oct < 0 ) {  
      while( note < 0 )  
   note += 12;
    } else {  
      while( note >= 128 )
   note -= 12;
    }
  }  
     
  if( inc_semi ) {
    note += inc_semi;
    if( inc_semi < 0 ) {
      while( note < 0 ) 
   note += 12;
    } else {  
      while( note >= 128 )
   note -= 12;
    }
  }  

Bye,

Peter

Link to comment
Share on other sites

:blink: Exactly the same thing can be achieved a little less verbose with the following:

 // apply transpose octave/semitones parameter
note += (12 * inc_oct) + inc_semi;
if (note > 127) {
    note = 116 + ((note - 4) % 12); 
} else if (note < 0) {
    note %= 12;
}

 

...which seems preferable cause it has a (fairly) constant run-time no matter what the transpose is.

Link to comment
Share on other sites

Agreed on the time-constantness - but TK.´s code does guarantee, that if there is an overflow (e.g. transposing 5 semitones up, out of the 128 range), that the resulting note will be exactly the same note, but on a lower octave close to the upper note limit, whereas the modulo by 128 will "only wrap around" and play a very low octave, possibly a very low tone.

Edited by Hawkeye
Link to comment
Share on other sites

When I wrote that this morning I was convinced that you could divide 128 by 12.

Then I had a coffee ;-)

 

Fixed that. I just prefer shorter code, especially if a single instruction division will achieve the same thing (stm32 and lpc17 have a hardware divider). So it's not only more concise it's also faster (in a lot of cases). On a PIC, the mod 12 part isn't necessarily the smartest thing to do though :-) Then again, if you really wanted fast you'd pre-calc the octave incrementer beforehand anyways.

 

Anyways, move along, nothing to see here.

Link to comment
Share on other sites

I agree with Nils - this was initially code from the PIC (without HW support for modulo).

I should optimize this for "modern CPUs" based on Nils' proposal before somebody else copies it for his projects ;-)

 

Best Regards, Thorsten.

Link to comment
Share on other sites

Am I correct that I can do what I want the app to do with a lpc core?

You are to correct that you can do what you want the app to do with a lpc core.  :poke:

 

It will work on the lpc-core. It will work on the stm32 core. A pic-based core will do the job just fine as well. So pick whichever you have, can/want to afford, like better, ...

Link to comment
Share on other sites

Nils, this aint a single midi i/o - I need 4 i/o - transpose 4 instruments at once (or seperate transpose settings for each port if I feel like it) - this is mostly input from keyboards to VSTi. - I usually play with 2 or 3 keys, and one of my weaknesses as a musician is that I use transposing a lot, have too little practice playing in for example B, and all those funky ones hehe. So what I'm after is a box where I can simply transpose in between songs or in the middle of songs. Some times that happens without it being planned. So This is primarily to make it as slick and flexible as possible for me in live situations. I can always set the transpose settings in the host (I use BloXpander - extremely happy with that - in live situations), but that aint that flexible. I need to configure each setting and save em as subscenes or scenes. On the stagepiano (one that I borrow every time I gig since I don't own my own that portable piano yet), all midi outputs are filtered through the transpose settings, so I can easily do what I want with midibox in that piano, but the same doesn't apply for the other controllers - there it involves more clicks here and there to get to the transpose settings.

 

So I figured, I want something that does the same as the yamaha stage - for all controllers. And maybe I one time need to put it between midi out and midi in on the synth, turn off local control too. All in all, tho the function of the box is gonna be simple and "cheap" - I think this will do exactly what I need no more no less.

 

I was under the impression that 4 midi i/o like this would be simpler and more realistic, more stable etc on the lpc core?

 

kpete. That's not gonna be an issue I believe - since the transposing happens (I can't think of any exceptions) between songs, or parts of songs whe I don't play anything. The few songs that this is a problem for, fast transitions in transpose settings, I play with two different controllers, so when the time is close, I transpose the controller I aint using at that moment, and it will be ready for me to just throw my hands at when time comes. :).

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...
 Share

×
×
  • Create New...