Triggering MIDI-Patterns with noteOn

Building on what I could find here: More about Controlling Patterns with MIDI

I’m trying to start/stop a Pattern with a noteOn/Off message from my keyboard. I managed to find a way to do that with Patterns that trigger the default Synth (or any other Synth) - but I run into trouble when I change the Pattern to \type, \midi.

Here’s the code that runs as intended, triggering the default Synth:

(
// noteOn
MIDIdef.noteOn(\noteOn, {
	arg val, num, chan, src;

	~keyboard = num;
	~pattern.play

}, chan: 0);

// noteOff
MIDIdef.noteOff(\noteOff, {
	arg val, num, chan, src;

	~pattern.stop

}, chan: 0);

// Pattern to be triggered
~pattern = Pbind(
    \midinote, Pfunc({
		Pwhite(~keyboard -2, ~keyboard + 2).asStream;
	}),
	\dur,0.2

).asEventStreamPlayer;
)

But what I really want to do, is to send MIDI. But this one doesn’t run. Only does one note for each key-stroke, with the error message ‘already playing’.

(
MIDIdef.noteOn(\noteOn2, {
	arg val, num, chan, src;

	~keyboard = num;
	~midiPattern.play

}, chan: 0);

MIDIdef.noteOff(\noteOff2, {
	arg val, num, chan, src;

	~midiPattern.stop

}, chan: 0);

~midiPattern = Pbind(
	\type, \midi,
	\midiout, m,
    \midinote, Pfunc({

		Pwhite(~keyboard -2, ~keyboard + 2).asStream;

	}),
	\dur,0.1

).asEventStreamPlayer;
)

m = my midiout.

Any help greatly appreciated.
Thx,
LP

I wonder if perhaps your MIDI device is accidentally sending MIDI thru back to SuperCollider? That would explain how a single note out from SC could retrigger the pattern.

hjh

1 Like

Yes, you’re right. I was using MIDIIn.connectAll, to fetch my keyboard messages - which also enabled the IAC driver as an input… :sweat_smile:

Solved with using MIDIIn.connect(0,1) instead.

Thanks a lot James!