I have finished the organ console complete with 43 MEC LED Switches and 8 pots. Also the Pedal switches have been assembled and have tested satisfactorily.
I have coded the button/ LED behaviour and the pedal coupling switches. Currently I am working on the Tremelo buttons.
Tremelo
There is one pot which provides the value yy in the Modulation messages using Bx 01 yy to the Roland Sound Canvas. There are two switches for two Midi Channels (0 and 1). When pressed they send the value of the pot (yy) to the sound module on the relevant channel. When depressed (pressed again) they send Bx 01 00.
If the pot value changes when the PB is selected then Bx 01 zz will be transmitted.
The AIN_Notify Change section will take care of the situation when the pot value has changed but how might I trigger the pot to be read after pressing the PB.
DIN_NotifyToggle
Currently this section has 420 lines(and more to come) mainly consisting of If/Else statements. Should I break this up into smaller sections. Does it matter? I have read somewhere that no section should be larger than one page for clarity reasons.
For tremolo I would propose to write a seperate function without any parameter (like void SendTremolo(void));
This function can get the current pot value with ‘MIOS_AIN_Pin7bitGet(xxx)’ (where xxx is the pot number, a constant), and the value of the two buttons with ‘MIOS_DIN_PinGet(yyy)’ (where yyy is the button number, also a constant).
This function has to be called from the AIN and DIN hook whenever the pot or button values changes.
The advantage of this single function is, that the code exists only once - this prevents inconsistencies.
420 lines within a function are really a lot, but so long it’s easy to read, I would let it like it is. You could try to generalize functions which are oftenly used. E.g. if Note events are sent, write a function SendNote(chn, note, velocity) instead of calling MIOS_MIDI_TxBufferPut three times. Such functions not only improve the readability, but also the quality of your code, because they prevent a certain types of programming errors (e.g. that at one place only two bytes instead of three will be sent)
I am making some progress on the tremelo programming but am having difficulty with dealing with the pot value. I can send fixed Midi messages but do not know how to “load” the 3rd TxBufferPut with the pot value.. See the following code.
// This function is called when Tremelo Message should be sent.
//B0 01 vv and/or B1 01 vv should be sent
/////////////////////////////////////////////////////////////////////////////
void SendTremelo() __wparam
{
unsigned char pin;
if (MIOS_DOUT_PinGet(61)==1)
{
MIOS_MIDI_TxBufferPut(0xB0);
MIOS_MIDI_TxBufferPut(0x01);
MIOS_AIN_Pin7bitGet(0x00);//This does not work!
MIOS_MIDI_TxBufferPut(pin_value);
}
if (MIOS_DOUT_PinGet(62) == 1)
{
MIOS_MIDI_TxBufferPut(0xB1);
MIOS_MIDI_TxBufferPut(0x01);
//MIOS_AIN_Pin7bitGet(0x00);This does not work!
MIOS_MIDI_TxBufferPut(pin_value);
}
}
This function is called in one instance by AIN_NotifyChange.
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a pot has been moved
/////////////////////////////////////////////////////////////////////////////
const unsigned char midi_status[7] = {0xB2, 0xB0, 0xB0, 0xB0, 0xB1, 0xB1, 0xB1};
const unsigned char midi_byte[7] = {0x0B, 0x08, 0x07, 0x0B, 0x09, 0x08, 0x0B};
void AIN_NotifyChange(unsigned char pin, unsigned int pin_value) __wparam
{
//Send Midi Control to Sound Module eg B2 0B XX, B0 08 YY etc
// Pots for Pins 2 -7
if( pin >=1 && pin <=7 )// Pots for Pins 2 -7
{
MIOS_MIDI_TxBufferPut(midi_status[pin - 1]);
MIOS_MIDI_TxBufferPut(midi_byte[pin - 1]);
MIOS_MIDI_TxBufferPut(pin_value);
}else
{
//Pot 1 Tremelo Modulation
if(pin == 0){
SendTremelo();// Function
}
}
Could you explain how to read the tremelo pot in the SendTremelo function.