Welcome to %s forums

BrainModular Users Forum

Login Register

midi out

Create your own modules in C++
Post Reply
User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 20 Aug 2017, 07:43

Hi,
I had a try at midi out.
I found out that the output array should be resized before sending a message and closed afterwards

If the array size is set to zero just after the array is filled with the midicode, the message is not send

if I wait few ticks before emptying the output array (a whole blocksize), the message is sent but during that time, the message is sent many times (roughly once every 5 clock ticks).

What is the proper way to send midi message out of a module ?

thanx

Olivar

...
else if (m_mode == 1) {
onTime = clock();
midiCode.Msg = MIDI_CONTROLCHANGE;
midiCode.Data1 = 123;
midiCode.Data2 = 0;
sdkSetEvtSize(midiOut, 1);
sdkSetEvtArrayMidi(midiOut, 0, midiCode);
m_create = 0;
}
...

int passed = clock() - onTime;
if (passed > sdkGetBlocSize() && token == 1) {
sdkSetEvtSize(midiOut, 0);
token = 0;
}
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

sm_jamieson
Member
Posts: 551
Contact:

Unread post by sm_jamieson » 21 Aug 2017, 20:55

You don't need to measure the length of a bloc like that. The onProcess() is called every tick, so if you set the midi output array in onProcess() just clear it on the next onProcess(). You can do this by simply setting a flag in onProcess() when you set the midi array. Then if when onProcess() is called you find the flag set, clear the midi array. If you get an onCallback() before the second onProcess() and wish to send further midi, you must clear the midi array before you add the new midi message.

If you set the midi array in onCallback() you must not clear the array in the following onProcess() but in the call of onProcess() after that (so the midi array remains set for a whole bloc). It seems that during a given bloc processing period, onCallback() is called just before onProcess(), since the method I have described is totally reliable.

If you are setting the midi array in onCallback(), bear in mind that you can get several onCallback() during a bloc, and if this happens you have to not clear the midi array, and may have to add the new midi message as a second entry in the array, etc.

This sounds a bit complicated but the way I do it is this:

At the start of onCallback() this code:

if (! hadCallback) {
sdkSetEvtSize(midiArrayEvent, 0);
hadCallback = true;
}

At the start of onProcess() have this code:

if (hadCallback) {
hadCallback = false;
}
else {
sdkSetEvtSize(midiArrayEvent, 0);
}

Then to send a midi message from onProcess() or onCallback() use this:

int size = sdkGetEvtSize(midiArrayEvent);
if (size < 0) size = 0;
sdkSetEvtSize(midiArrayEvent, size + 1);
sdkSetEvtArrayMidi(midiArrayEvent, size, code);


All this could have been hidden behind some stuff in the SDK I suppose.

Similarly if you want to send a trigger output, you can do the same sort of thing to make sure it stays
set for one bloc.

Simon.

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 21 Aug 2017, 21:15

thanks a lot !
that helps !
cheers
Olivar
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

sm_jamieson
Member
Posts: 551
Contact:

Unread post by sm_jamieson » 21 Aug 2017, 21:31

Your first method of calculating a whole block could work, but is not very efficient as you have to keep checking the time.
The main problem is that the bloc length is being calculated incorrectly. sdkGetBlocSize() returns the number of samples in a bloc. To get the bloc length in seconds you must do ((double)sdkGetBlocSize() / sdkGetSampleRate ()).
There is only one tick per bloc.

Simon.

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 21 Aug 2017, 23:09

thanks, I'll try you solution asap
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests