The sound from OSCFunc Project appears in the MIDIDef Project

Hi, I do not know why after using OSCFunc project and close it, when I open this MIDIDef project again, the SynthDef in it can not work anymore. I mean the sound after I trigger the keyboard is the sound from OSCFunc project rather than from SynthDef in this MIDI project. Really confused here… MIDIDef works pretty well here because I can hear it controls as before(All thing went awesome before and sound source is right from SynthDef like the pic). I am sure I restart and reboot everything in visual studio code, but it is the same result. If someone can help, appreciate it! Both pics are my MIDIDef project.


My num MIDI message received from bend is ranged from 0-16383, weired… No method to solve it now for me. So I wrote ~numbers2 = Array.fill(16384, {nil});

Maybe try giving the SynthDefs different names?

That’s a guess – it isn’t clear exactly what steps you’re taking, in what order. It’s a reasonable guess though – your code is creating Synth(\tone...) instances. If it’s using the wrong SynthDef, then it can only be that the other SynthDef is named \tone as well.

Giving two different things the same name is a good way to create confusion – avoid doing that.

Bend numbers are not note numbers, so 1/ per the MIDI specification, bend numbers are correctly 14-bit integers and not 7-bit – however, SC offsets the number to be positive, so the number for “no bend” is 8192, not 0, and 2/ there’s no need for a ~numbers2 array, just delete it.

hjh

1 Like

Hiii, it works well now! Thanks a lot! Yes, the no bend is 8192. About the ~numbers2, it is because I used it as do in MIDI.bend, to if I change the 16384 here to 8192, it means when I bend up, nothing is gonna affect the synth, iterate over the array of the notes and pass in each synths(which I learned from others). And it is pretty fun to make the control affect the triggered synth in the real-time but the bend is changed before I triggered my keyboard everytime to make the bend meaningful.

The synths are indexed by note number, which ranges 0 to 127.

The pitch bend control has nothing to do with the way the synths are indexed. So it’s irrelevant to have a collection with an element for every possible pitch bend value.

Your code already knows this, in a sense – you created ~numbers2 but you never put anything into it – so your pitch bend function is looping over an array of 16k nil values and as a result, it’s not sending anything.

Your pitch bend function should do over the ~numbers array because this is where your synths are stored. After you make that change, then ~numbers2 will not be used anywhere, and you can delete it.

hjh

Oh, I understand it now. I am new here and still learning. Thanks a lot!