Hi everybody!
After a long time I decided to try out my midiboxing skills…
I just started coding yesterday and I have no experience whatsoever with this.. So please be nice… Additionally I have not yet started building the damn thing so many of my questions will probably be solved when switching it on the first time. But I’m afraid I’ll fry it up ![]()
Anyway, I need a lot of help with my code cause I have no freakin idea if anything I coded is correct… But before I post the respective code snippets I will try to describe what my small midi box should do in the end and post a picture so you know what I have in mind…
The box is going to act as a floorboard controller for my guitar effects rig. Although I have some commercial controllers I thought they could do better for my purposes so I ended up here ![]()
The box has 6 buttons (DIN 0x00 - 0x05 sorry for the typo in the pic) and two external inputs for buttons (DIN 0x6 and 0x7).
Buttons 4-6 send Control Changes; Button 1 switches between 2 Program Changes (for the distorted guitar channel), same goes for Button 2 (for the clean guitar channel). Button 3 is a shift button, that switches between 3 banks. The Program Changes of Buttons 1 and 2 act correspondingly.
External Button 2 sends a Control Change message, Ext Button 1 is a little bit more complicated. It is somehow a remote control for Button 1 and 2. It switches between the two Program Change messages of these Buttons, dependent on the last pressed Button (which channel is selected).
The LEDs 0x07 - 0xA are regular LEDs. The first 3 light up when Control Changes are received, LED 0xA ist just a status LED that turns on, when the midibox is on.
The lower row of LEDs should be RGB Leds that light up in a different color, when the corresponding button is pressed.
So far for the concept… Now comes the really big part, a million questions (I have read the wiki and the forum but still need help, since I’m really a newbie at this…Sorry).
The whole main.c (WIP) can be downloaded at hxxp://www.dailymojo.org/main.zip if it is easier for you…
I’ll continue now by posting code snippets and then asking the questions for this part, ok?
Alright…
/////////////////////////////////////////////////////////////////////////////
// Local variables
/////////////////////////////////////////////////////////////////////////////
// last_button + shift + dirty lead + clean lead + ext1
unsigned char last_button;
unsigned char shift;
unsigned char dirty;
unsigned char clean;
unsigned char ext1;
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS after startup to initialize the
// application
/////////////////////////////////////////////////////////////////////////////
void Init(void) __wparam
{
// set shift register update frequency
MIOS_SRIO_UpdateFrqSet(1); // ms
// we need to set at least one IO shift register pair
MIOS_SRIO_NumberSet(NUMBER_OF_SRIO);
// debouncing value for DINs
MIOS_SRIO_DebounceSet(DIN_DEBOUNCE_VALUE);
MIOS_SRIO_TS_SensitivitySet(DIN_TS_SENSITIVITY);
// only one DOUTX4 module is connected
// the maximum value is 16 (-> 128 digital outputs)
MIOS_SRIO_NumberSet(16);
// intialize start-up status etc
MIOS_DOUT_PinSet(0xA, 1); // Status LED
MIOS_DOUT_PinSet(0x00, 1); // LED Dirty Rhythm On
MIOS_DOUT_PinSet(0x01, 0); // Other Channel LEDs off
MIOS_DOUT_PinSet(0x02, 0);
MIOS_DOUT_PinSet(0x03, 0);
MIOS_MIDI_BeginStream();
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 16
MIOS_MIDI_TxBufferPut(0x1 + shift); // ProgramChange 1 + shift DIRTY RHYTHM EQ
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 1
MIOS_MIDI_TxBufferPut(0x59); // ProgramChange 89
MIOS_MIDI_TxBufferPut(0xC1); // Midichannel 2
MIOS_MIDI_TxBufferPut(0x0); // ProgramChange 0
MIOS_MIDI_TxBufferPut(pin_value ? 0x00 : 0x7f); // High-Active State
MIOS_MIDI_EndStream();
last_button = 0;
}
The first ‘couple’ of questions:
-
Do I have to declare the local variables somewhere else as well? (total C noob question..)
-
In the void Init part I included my personal start-up status. Does this belong here or after the void init function?
-
As I stated above, I want to use RGB LEDs to make it cooler-looking. In the code I treat every color of the LED as a single DOUT, is this the correct way?
-
Whatfor is the MIOS_MIDI_BeginStream command? In some examples this command was left out… I included it anyway..
-
Is this the correct way to send multiple midi messages at once? As you can see I send three messages simutaneously…
-
In the beginning I introduced the char ‘shift’ , which indicates the status of the shift button (see above). Now in my first midi out message (and in some others too) I want to send a Program Change command which is “ProgChange 1 + shift value” but I don’t know if this is the correct way, probably not since I add a decimal value to the Hex value..
-
the last line shall set the last_button char value as a 0, is this correct?
Ok, this was the first part, many of these commands will come up again and again so ignore them in the next code parts…
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a complete MIDI event has been received
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyReceivedEvnt(
unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam
{
// BLOCK STATUS RECEIVE -> LED 4-6
if( evnt0 == 0xBF ) {
// evnt0 == 0xBF = Control Change on MidiChannel 16
if( evnt2 == 0x00 ) {
// Control Change Value 0
MIOS_DOUT_PinSet(evnt1 +=6, 0);
} else {
// Control Change Value 127
MIOS_DOUT_PinSet(evnt1 +=6, 1);
}
}
}
The corresponding DOUT_PinSet value should be the received Control Change Number (evnt1) + a decimal 6 (as you can see above the LEDs that should react to these messages are 0x07 to 0x09, so I want to add a 6 to the cc number). How do I do that?
Ok, the next part describes what happens if a button is pressed… I tried to code it the most easiest way I could (or as I could learn from this forum) but due to my inability to code in C there are probably some errors.. I have no specific questions here, please just have a look at it (especially case 0x06 - is there an easier way to do this?) and tell me if I should jump from a bridge or if there is someway to make me a midiboxer ![]()
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when an button has been toggled
// pin_value is 1 when button released, and 0 when button pressed
/////////////////////////////////////////////////////////////////////////////
void DIN_NotifyToggle(unsigned char pin, unsigned char pin_value) __wparam
{
switch( pin ) {
case 0x02: // Bank Button as a Shift button to toggle between three equalizer modes
shift++;
if(shift > 2) { shift = 0; }
switch(shift) {
case 0:
MIOS_DOUT_PinSet(0x04, 1);
MIOS_DOUT_PinSet(0x05, 0);
MIOS_DOUT_PinSet(0x06, 0);
break;
case 1:
MIOS_DOUT_PinSet(0x04, 0);
MIOS_DOUT_PinSet(0x05, 1);
MIOS_DOUT_PinSet(0x06, 0);
break;
case 2:
MIOS_DOUT_PinSet(0x04, 0);
MIOS_DOUT_PinSet(0x05, 0);
MIOS_DOUT_PinSet(0x06, 1);
break;
} // switch shift
case 0x00: // Dirty Rhythm/Lead
dirty++;
if(dirty >1) {dirty = 0}
switch(dirty) {
case 0:
MIOS_DOUT_PinSet(0x00, 1); // LED Dirty Rhythm On
MIOS_DOUT_PinSet(0x01, 0); // Other Channel LEDs off
MIOS_DOUT_PinSet(0x02, 0);
MIOS_DOUT_PinSet(0x03, 0);
MIOS_MIDI_BeginStream();
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 16
MIOS_MIDI_TxBufferPut(0x1 + shift); // ProgramChange 1 + shift DIRTY RHYTHM EQ
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 1
MIOS_MIDI_TxBufferPut(0x59); // ProgramChange 89
MIOS_MIDI_TxBufferPut(0xC1); // Midichannel 2
MIOS_MIDI_TxBufferPut(0x0); // ProgramChange 0
MIOS_MIDI_TxBufferPut(pin_value ? 0x00 : 0x7f); // High-Active State
MIOS_MIDI_EndStream();
last_button = 0;
break;
case 1:
MIOS_DOUT_PinSet(0x00, 0); // LED Dirty Lead On
MIOS_DOUT_PinSet(0x01, 1); // Other Channel LEDs off
MIOS_DOUT_PinSet(0x02, 0);
MIOS_DOUT_PinSet(0x03, 0);
MIOS_MIDI_BeginStream();
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 16
MIOS_MIDI_TxBufferPut(0x7 + shift); // ProgramChange 7 + shift DIRTY LEAD EQ
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 1
MIOS_MIDI_TxBufferPut(0x7E); // ProgramChange 126
MIOS_MIDI_TxBufferPut(0xC1); // Midichannel 2
MIOS_MIDI_TxBufferPut(0x0); // ProgramChange 0 EVENTUELL ÄNDERN WEGEN LOOPER AUF 1
MIOS_MIDI_TxBufferPut(pin_value ? 0x00 : 0x7f); // High-Active State
MIOS_MIDI_EndStream();
last_button = 1;
break;
} // switch dirty
case 0x01: // Clean Rhythm/Lead
clean++;
if(clean >1) {clean = 0}
switch(clean) {
case 0:
MIOS_DOUT_PinSet(0x00, 0); // LED Clean Rhythm On
MIOS_DOUT_PinSet(0x01, 0); // Other Channel LEDs off
MIOS_DOUT_PinSet(0x02, 1);
MIOS_DOUT_PinSet(0x03, 0);
MIOS_MIDI_BeginStream();
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 16
MIOS_MIDI_TxBufferPut(0x44 + shift); // ProgramChange 4 + shift Clean RHYTHM EQ
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 1
MIOS_MIDI_TxBufferPut(0x59); // ProgramChange 89
MIOS_MIDI_TxBufferPut(0xC1); // Midichannel 2
MIOS_MIDI_TxBufferPut(0x1); // ProgramChange 1 EVENTUELL ÄNDERN WEGEN LOOPER AUF 2
MIOS_MIDI_TxBufferPut(pin_value ? 0x00 : 0x7f); // High-Active State
MIOS_MIDI_EndStream();
last_button = 2;
break;
case 1:
MIOS_DOUT_PinSet(0x00, 0); // LED Clean Lead On
MIOS_DOUT_PinSet(0x01, 0); // Other Channel LEDs off
MIOS_DOUT_PinSet(0x02, 0);
MIOS_DOUT_PinSet(0x03, 1);
MIOS_MIDI_BeginStream();
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 16
MIOS_MIDI_TxBufferPut(0xA + shift); // ProgramChange 10 + shift Clean LEAD EQ
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 1
MIOS_MIDI_TxBufferPut(0x77); // ProgramChange 119
MIOS_MIDI_TxBufferPut(0xC1); // Midichannel 2
MIOS_MIDI_TxBufferPut(0x1); // ProgramChange 1 EVENTUELL ÄNDERN WEGEN LOOPER AUF 3
MIOS_MIDI_TxBufferPut(pin_value ? 0x00 : 0x7f); // High-Active State
MIOS_MIDI_EndStream();
last_button = 3;
break;
} // switch clean
case 0x03: // Harmonizer Function Switch 1
MIOS_MIDI_BeginStream();
MIOS_MIDI_TxBufferPut(0xBF); // CC on channel 16
MIOS_MIDI_TxBufferPut(0x1); // CC #1
MIOS_MIDI_TxBufferPut(pin_value ? 0x00 : 0x7f); // Velocity = 0x7f when
// button pressed, else 0x00
MIOS_MIDI_EndStream();
break;
case 0x04: // Tremolo Function Switch 2
MIOS_MIDI_BeginStream();
MIOS_MIDI_TxBufferPut(0xBF); // CC on channel 16
MIOS_MIDI_TxBufferPut(0x2); // CC #2
MIOS_MIDI_TxBufferPut(pin_value ? 0x00 : 0x7f); // Velocity = 0x7f when
// button pressed, else 0x00
MIOS_MIDI_EndStream();
break;
case 0x05: // Tuner Function Switch 3
MIOS_MIDI_BeginStream();
MIOS_MIDI_TxBufferPut(0xBF); // CC on channel 16
MIOS_MIDI_TxBufferPut(0x3); // CC #3
MIOS_MIDI_TxBufferPut(pin_value ? 0x00 : 0x7f); // Velocity = 0x7f when
// button pressed, else 0x00
MIOS_MIDI_EndStream();
break;
case 0x06: // External Switch 1 switches between Lead and Rhythm Sound for both channels
ext1++;
if(ext1 >1) {ext1 = 0}
switch(ext1) {
case 0:
if (last_button == 0 || last_button == 1) {
MIOS_DOUT_PinSet(0x00, 1); // LED Dirty Rhythm On
MIOS_DOUT_PinSet(0x01, 0); // Other Channel LEDs off
MIOS_DOUT_PinSet(0x02, 0);
MIOS_DOUT_PinSet(0x03, 0);
MIOS_MIDI_BeginStream();
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 16
MIOS_MIDI_TxBufferPut(0x1 + shift); // ProgramChange 1 + shift DIRTY RHYTHM EQ
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 1
MIOS_MIDI_TxBufferPut(0x59); // ProgramChange 89
MIOS_MIDI_TxBufferPut(0xC1); // Midichannel 2
MIOS_MIDI_TxBufferPut(0x0); // ProgramChange 0
MIOS_MIDI_TxBufferPut(pin_value ? 0x00 : 0x7f); // High-Active State
MIOS_MIDI_EndStream();
} // endif lastbutton
if (last_button == 2 || last_button == 3) {
MIOS_DOUT_PinSet(0x00, 0); // LED Clean Rhythm On
MIOS_DOUT_PinSet(0x01, 0); // Other Channel LEDs off
MIOS_DOUT_PinSet(0x02, 1);
MIOS_DOUT_PinSet(0x03, 0);
MIOS_MIDI_BeginStream();
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 16
MIOS_MIDI_TxBufferPut(0x4 + shift); // ProgramChange 4 + shift Clean RHYTHM EQ
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 1
MIOS_MIDI_TxBufferPut(0x59); // ProgramChange 89
MIOS_MIDI_TxBufferPut(0xC1); // Midichannel 2
MIOS_MIDI_TxBufferPut(0x1); // ProgramChange 1 EVENTUELL ÄNDERN WEGEN LOOPER AUF 2
MIOS_MIDI_TxBufferPut(pin_value ? 0x00 : 0x7f); // High-Active State
MIOS_MIDI_EndStream();
} // endif lastbutton
break;
case 1:
if (last_button == 0 || last_button == 1) {
MIOS_DOUT_PinSet(0x00, 0); // LED Dirty Lead On
MIOS_DOUT_PinSet(0x01, 1); // Other Channel LEDs off
MIOS_DOUT_PinSet(0x02, 0);
MIOS_DOUT_PinSet(0x03, 0);
MIOS_MIDI_BeginStream();
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 16
MIOS_MIDI_TxBufferPut(0x7 + shift); // ProgramChange 7 + shift DIRTY LEAD EQ
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 1
MIOS_MIDI_TxBufferPut(0x7E); // ProgramChange 126
MIOS_MIDI_TxBufferPut(0xC1); // Midichannel 2
MIOS_MIDI_TxBufferPut(0x0); // ProgramChange 0
MIOS_MIDI_TxBufferPut(pin_value ? 0x00 : 0x7f); // High-Active State
MIOS_MIDI_EndStream();
} // endif lastbutton
if (last_button == 2 || last_button == 3) {
MIOS_DOUT_PinSet(0x00, 0); // LED Clean Lead On
MIOS_DOUT_PinSet(0x01, 0); // Other Channel LEDs off
MIOS_DOUT_PinSet(0x02, 0);
MIOS_DOUT_PinSet(0x03, 1);
MIOS_MIDI_BeginStream();
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 16
MIOS_MIDI_TxBufferPut(0xA + shift); // ProgramChange 10 + shift Clean RHYTHM EQ
MIOS_MIDI_TxBufferPut(0xC0); // Midichannel 1
MIOS_MIDI_TxBufferPut(0x77); // ProgramChange 119
MIOS_MIDI_TxBufferPut(0xC1); // Midichannel 2
MIOS_MIDI_TxBufferPut(0x1); // ProgramChange 1 EVENTUELL ÄNDERN WEGEN LOOPER AUF 2
MIOS_MIDI_TxBufferPut(pin_value ? 0x00 : 0x7f); // High-Active State
MIOS_MIDI_EndStream();
} // endif lastbutton
break;
} // switch ext1
case 0x07: // Externeal switch 2 switches Delay ON/OFF via CC #4
MIOS_MIDI_BeginStream();
MIOS_MIDI_TxBufferPut(0xBF); // CC on channel 16
MIOS_MIDI_TxBufferPut(0x4); // CC #4
MIOS_MIDI_TxBufferPut(pin_value ? 0x00 : 0x7f); // Velocity = 0x7f when
// button pressed, else 0x00
MIOS_MIDI_EndStream();
break;
} // switch pin
} // void din notify toggle
Ok, this was a long post and I know it’s not that polite to start here with a million questions etc… But I tried to do as much as I can without asking (by reading the forum, the wiki and stuff) and now this is the part that seems unclear to me..
I tried to explain my code as precise as I can, so feel free to ask if you need something explained more in detail…
Anyway, thanks to anyone who’s able one or more questions! Sorry for my english…
Well I owe you a beer or two…
Thanks,
JSF