Overriding Event Types

Hello,

Goal: Add an additional function to the default event type, which I believe is \note to write MIDI information to a SimpleMIDIFile. I’m not outputting MIDI in this case and the function is intended to write the data when a specific key ( \recordTarget ) is present.

I’m trying to hook in a function to the default \note Event type. Something like this which was from another post regarding MIDI recording, given by @scztt (but this is my modification):

Event.addEventType(
			\note,
			Event.eventTypes[\note].addFunc({
				var mnote;
				if (~recordTarget.notNil) {
					if( ~recordTarget.smf.notNil){
						~recordTarget.smf.addNote(
							noteNumber: ~midinote,
							velo: ~amp.range(0, 127),
							startTime: thisThread.clock.beats - ~recordTarget.startSeconds,
							dur: ~dur,
							channel: ~chan,
							track: ~chan,
						);
					}
				}
			}),
			() // if you want some recording-related properties to have default values, pass them here
		);

However, that seems to break the normal Event entirely and I’m not sure why when I use like this:

Ndef(\hh).play;
(
Pdef(\hh,
	Pbind(
		\instrument, \bplay,
		\out, Pfunc(Ndef(\hh).bus.index),
		\group, Pfunc(Ndef(\hh).group),
		\buf, d["Hats"][1],
		// \dur, Pseq([0.125, 0.125, 0.5, 0.75, 0.25].scramble, inf),
		// \dur,Pbjorklund2(Pseq(l, inf).asStream,12,inf)/8,
		\dur, 0.125,
		\midinote, 60,
		\dur, Pbjorklund2(3, 5, inf),
		\recordTarget, ~hr,
		\chan, 0,
));
)

Pdef(\hh).play(quant: -1);

If I remove the key \recordTarget (which refers to an instance of a class that instantiates an Ndef recorder and a SimpleMIDIFile instance inside) it works fine. If I include it, the event seems to stop dead - no errors, just doesn’t play like a \note. I didn’t share the rest of the class code, but I didn’t want to make this overly complex with all of the code.

I feel like I’m just using the Event.addEventType or the .addFunc improperly.

Note this all worked with @scztt’s code originally, where I was chaining Pbinds together and adding the event type to \midi and not \note. I was trying to simplify my code a bit and just have MIDI get saved out as long as \recordTarget is in the Pbind.

I hope all of that makes some sense.

Update: The override wasn’t the issue. The \note override above was working just fine. It was my usage apparently. However, I changed enough things to not exactly know what fixed it (and was either in my overarching class file or the usage).