matrigs Posted February 8, 2007 Report Share Posted February 8, 2007 could you give me any hint on this one?i'm doing a program in c from scratch with the skeleton. i have already launched the analog inputs, pots are working fine now there is a thing that i would want to implement.i want to add 8 encoders (i guess launching them will not be to difficul) and now, i want to have 4 buttons which will shift their send cc numbers. so let's say that they are sending cc 0-7 from the beginning, when i press the button they sen 8-15 then i press a third button and the send 16-23.i guess i have to somehow "shift" the pin number in the MIOS_MIDI_TxBufferPut(pin) function as this is sending the appropriate cc to the core (i hope i got that one right)could anybody give me a hint ? Quote Link to comment Share on other sites More sharing options...
audiocommander Posted February 8, 2007 Report Share Posted February 8, 2007 Hi matrigs,you need a local variable.For example: unsigned char shift; // now you have to increment the shift var at the DIN_Notify() function like this // shift can be 0 (0-7), 1 (8-15) or 2 (16-23) shift++; if(shift > 2) { shift = 0; } // now at the AIN_Notify() or ENC_Notify() get the CC number like this: unsigned char cc = (shift << 3) + enc_num; a left bitshift (<<)* is nothing else than a multiplication with 2; so x<<3 is a multiplication with 2 for 3 times.so 1<<1=2, 2<<1=4, 6<<1=12, 1<<6=64.a right bitshift (>>) is the same but only division with 2.You might also take a look at a basic C book (there are plenty of online resources) and look into the code examples from the c section!Best regards,Michael* don't mix it up with the logical expression "is smaller than" (<) Quote Link to comment Share on other sites More sharing options...
matrigs Posted February 8, 2007 Author Report Share Posted February 8, 2007 thanks i'll have to try that one out! Quote Link to comment Share on other sites More sharing options...
matrigs Posted February 8, 2007 Author Report Share Posted February 8, 2007 just em, could you maybe also show me how to connect this shift function to a button press? Quote Link to comment Share on other sites More sharing options...
audiocommander Posted February 8, 2007 Report Share Posted February 8, 2007 I did:// now you have to increment the shift var at the DIN_Notify() function like thisand if you're stuck please try to follow my other advices first, esp. that one looking at the example codes at the c-section of ucapps: http://www.ucapps.de/mios_c.html=> sending midi events on button movements (the doc headline fits better: Send Note Events on digital input changes) Quote Link to comment Share on other sites More sharing options...
matrigs Posted February 8, 2007 Author Report Share Posted February 8, 2007 i'm sorry but the thing is that those explained examples are perfectly clear for me but changing a single character makes me unsure about it. i understand the c example with sending the midi notes and i understand WHAT i should do but i don't know how to just put the code together. yeah but i guess that's the way Quote Link to comment Share on other sites More sharing options...
matrigs Posted February 25, 2007 Author Report Share Posted February 25, 2007 call me dumb but as the shift variable is local it gets erased once the din notify is ended.so how can i ten use this variable a few lines beneath in the enc notify function ? Quote Link to comment Share on other sites More sharing options...
audiocommander Posted February 25, 2007 Report Share Posted February 25, 2007 hello matrigs,you want to look up about the scopes of variables.In C you can have (basically) three different types of scopes:- block scope (variable is declared inside a { } block)- local scope (variable is declared inside a function() { } )- file scope (variable is declared inside a file.c, typically on top of the page).Now look at the code I posted again;I'm splitting it up and tell you where to put the code:unsigned char shift;[/code]now you have to increment the shift var [b]at the DIN_Notify()[/b] function like thisshift can be 0 (0-7), 1 (8-15) or 2 (16-23)[code=add to main.c inside the DIN_NotifyToggle()]shift++;if(shift > 2) { shift = 0; }now at the AIN_Notify() or ENC_Notify() get the CC number like this:unsigned char cc = (shift << 3) + encoder;// the variable cc now contains the shifted cc number.[/code]Of course this is a simplified example where the shift value gets incremented by any button press. You have to improve this to make it work with four buttons, but I hope the principle is now clear.Best regards,Michael Quote Link to comment Share on other sites More sharing options...
matrigs Posted February 26, 2007 Author Report Share Posted February 26, 2007 thanks tons for this !!you know what - i did exactly what you said the whole time over and it still didn't work and i was really at the edge of crying before the solution just popped into my head.all the time i was curious why the hell did my button press send some midi cc data when it wasn't supposed to (no din_notify_toggle in my setup) - even when i completely tossed out everything related to button press it still sended midi data. i nearly spoiled coffee on my screen when it suddenly got me - when i launched the encoder i engaged all pins of the first two shift registers to encoder mode but there was only one encoder connected and the rest of the pins are buttons !!!!so that's why it didn't work all the time :Dthanks so much for your help i think this project should speed up a lot now :P 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.