I’m using patterns to trigger sounds.
Sometimes, I want to run a custom action at the same time as the note on event (e.g. sending OSC messages to a 3rd party application).
To do this I’ve defined a custom event which runs the function defined by the \action key, and then modifies the event type back to \note and plays it, ie delegates to the default event player:
Event.addEventType(\actionInstrument, {
var noteEvent;
~action.value();
noteEvent = currentEnvironment.copy;
noteEvent.use {
~type = \note;
};
noteEvent.play;
});
Is this the correct way of achieving what I’m trying to do?
One problem I’m having is that my custom code runs in the event’s environment, so while all the event’s keys are accessible as globals, my code no longer has access to the program’s original global environment, so I can’t use any utility functions I’ve defined on the global scope. If I want to access them, I have to bind them in the pattern, e.g.
Pbind(
\type, actionInstrument,
\utilityFunction1, ~utilityFunction1,
\utilityFunction2, ~utilityFunction2,
\utilityFunction3, ~utilityFunction3,
);
Is there a way around this?