Jump to content

Tremelo Operation How to code in C


robinfawell
 Share

Recommended Posts

Dear TK

I'm back!

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.

Regards Robin

Link to comment
Share on other sites

Hi Robin,

nice to read about the good progress! :)

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)

Best Regards, Thorsten.

Link to comment
Share on other sites

  • 2 weeks later...

Dear Thorsten

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.

Link to comment
Share on other sites

Hi Robin,

pin_value is an "unsigned int" with 10bit resolution, but for a CC an "unsigned char" with 7bit resolution must be sent.

The easiest way to get the 7bit value is the use of MIOS_AIN_Pin7bitGet(pin), see also http://www.ucapps.de/mios_c_send_ain.html.

It's possible to use this function within SendTremelo() as well (replace "pin" by a constant value)

Best Regards, Thorsten.

Link to comment
Share on other sites

Thanks Thorsten,

SendTremelo is working!

However in reading the "Send CC Events on Pot Movements" I noticed the use of 'unsigned int pin_value' as  a variable in the function statement.

I have tried both unsigned int and unsigned char as the pin_value variable in my SendTremelo. Both work.

I suppose that the 7bit value obtained by the PinGet function limits the value to 7 bits in any case.

Is there any difference between the following?

MIOS_AIN_Pin7bitGet(0x00);

MIOS_MIDI_TxBufferPut(pin_value);

and

MIOS_MIDI_TxBufferPut(MIOS_AIN_Pin7bitGet(0x00));

Regards Robin

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