Strange isRest behaviour when used in custom Event type


#1

Hello, when I run this code

(
Event.addEventType(\customEvent, {
	("currentEnvironment:" + currentEnvironment.isRest).postln;
});

Pbind(
	\type, \customEvent,
	\dur, Pseq([0.25, Rest(0.25),0.25])
).collect({|event| ("Pcollect:" + event.isRest).postln; event}).play;
)

I get

Pcollect: false
currentEnvironment: false

Pcollect: true

Pcollect: false
currentEnvironment: false

I would expect to see currentEnvironment: true on the post window when the second event is played, so I’m a bit confused.
I can’t find the way to use currentEnvironment.isRest when it’s true. I’m trying to send events through OSC with a key like \rest, true or similar defined in a custom event type.
I’m using SC 3.10.2 on Linux, no quarks installed.
Any help would be greatly appreciated


#2

A ‘rest’ event bypasses all event type functions.

hjh


#3

Thanks a lot for your answer!
Does it mean that the only way to send a ‘rest’ event through OSC is by adding a key inside Pbind?
e.g. \sendOSC, Pfunc({|e| netaddr.sendMsg("/oscPath", e.asString)})


#4

Hm, actually, that’s not the only way.

The Event:play method always calls the event’s play function. This does a bunch of things:

  1. Retrieves a set of defaults for the event type.
  2. Sets the server variable.
  3. Calls a \finish hook (finish preparation before playing).
  4. Updates tempo, if \tempo is set.
  5. Calls the event type function, if the event is not a rest.
  6. Calls a \callback hook (giving the caller access to the event’s final state).

Of these, only #5 is skipped for rests. All of the other ones are done for every event.

So you could also do \finish, { |event| ... send your OSC here ... } in the Pbind (note, that is not \finish, Pfunc { ... } – the finish key should get the literal function). \callback might be OK too, but rest events will not do pitch or duration calculations (that is, if you specify \degree, sounding events will end up with a \freq value, but rest events will not – so your callback function cannot assume that \freq will always be there).

hjh


#5

\finish seems very useful for this case
Thank you very much James!