technobreath Posted March 31, 2013 Report Share Posted March 31, 2013 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. Quote Link to comment Share on other sites More sharing options...
Hawkeye Posted April 1, 2013 Report Share Posted April 1, 2013 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 Quote Link to comment Share on other sites More sharing options...
technobreath Posted April 2, 2013 Author Report Share Posted April 2, 2013 Thanks hawk! I'll dig the seq4 code and have a look! :) Many greets from Hoth :) Quote Link to comment Share on other sites More sharing options...
technobreath Posted April 2, 2013 Author Report Share Posted April 2, 2013 Haha! Code is ok, but there's just so much code :( You happen to know where to look too? :) Quote Link to comment Share on other sites More sharing options...
Hawkeye Posted April 3, 2013 Report Share Posted April 3, 2013 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 Quote Link to comment Share on other sites More sharing options...
nILS Posted April 3, 2013 Report Share Posted April 3, 2013 :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. Quote Link to comment Share on other sites More sharing options...
Hawkeye Posted April 3, 2013 Report Share Posted April 3, 2013 (edited) 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 April 3, 2013 by Hawkeye Quote Link to comment Share on other sites More sharing options...
nILS Posted April 3, 2013 Report Share Posted April 3, 2013 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. Quote Link to comment Share on other sites More sharing options...
TK. Posted April 3, 2013 Report Share Posted April 3, 2013 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. Quote Link to comment Share on other sites More sharing options...
technobreath Posted April 4, 2013 Author Report Share Posted April 4, 2013 Thanks guys. I'm not used to digging in the code for midibox (yet). But this seems easy enough. Am I correct that I can do what I want the app to do with a lpc core? Nils: Quote Link to comment Share on other sites More sharing options...
nILS Posted April 4, 2013 Report Share Posted April 4, 2013 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, ... Quote Link to comment Share on other sites More sharing options...
kpete Posted April 4, 2013 Report Share Posted April 4, 2013 Just remember that you can't change the pitch while you have notes playing. You will have to send a All Notes Off message to the appropriate channel so notes won't cypher. Quote Link to comment Share on other sites More sharing options...
technobreath Posted April 4, 2013 Author Report Share Posted April 4, 2013 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. :). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.