Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Swing guide doesn't work for \midi events #5975

Open
madskjeldgaard opened this issue Feb 16, 2023 · 4 comments
Open

Docs: Swing guide doesn't work for \midi events #5975

madskjeldgaard opened this issue Feb 16, 2023 · 4 comments
Labels
bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs.

Comments

@madskjeldgaard
Copy link
Contributor

The excellent Pattern cookbook's chapter on swing relies on using \timingOffset which does not seem to work with events of type \midi unfortunately because they don't use that key in the scheduling part of the event.

https://doc.sccode.org/Tutorials/A-Practical-Guide/PG_Cookbook08_Swing.html

This is what the midi event looks like in Event.sc:

midi: #{|server|
						var freqs, lag, dur, sustain, strum;
						var bndl, midiout, hasGate, midicmd;

						freqs = ~freq = ~detunedFreq.value;

						~amp = ~amp.value;
						~midinote = (freqs.cpsmidi).round(1).asInteger;
						strum = ~strum;
						lag = ~lag;
						sustain = ~sustain = ~sustain.value;
						midiout = ~midiout.value;
						~uid ?? { ~uid = midiout.uid };  // mainly for sysex cmd
						hasGate = ~hasGate ? true;
						midicmd = ~midicmd;
						bndl = ~midiEventFunctions[midicmd].valueEnvir.asCollection;

						bndl = bndl.asControlInput.flop;

						bndl.do {|msgArgs, i|
							var latency;

							latency = i * strum + lag;

							if(latency == 0.0) {
								midiout.performList(midicmd, msgArgs)
							} {
								thisThread.clock.sched(latency, {
									midiout.performList(midicmd, msgArgs);
								})
							};
							if(hasGate and: { midicmd === \noteOn }) {
								thisThread.clock.sched(sustain + latency, {
									midiout.noteOff(*msgArgs)
								});
							};
						};
					}
@madskjeldgaard madskjeldgaard added the bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. label Feb 16, 2023
@telephon
Copy link
Member

It would be great to have a UnitTest that checks midi event and note event equivalence!

@madskjeldgaard
Copy link
Contributor Author

madskjeldgaard commented Feb 17, 2023 via email

@smrg-lm
Copy link
Contributor

smrg-lm commented Feb 19, 2023

I have seen this issue, it isn't related to the midi event implementation but the use of \timingOffset as a key, it doesn't exist except for \note events (and maybe other related events/streams that create the key or use the default event) and is ignored (returns nil or creates the key) for everything else. The key is also used by EventStreamPlayer through Quant (iirc) and other related timing methods, maybe it should be implemented for \midi events too. It's a difficult one.

@totalgee
Copy link
Contributor

👍
I just came across this problem in the last week, too, that timingOffset does not work for \midi type Events (and it should!). There is the lag key that works to shift MIDI Events in time, but it doesn't know anything about the tempo so it's more of a pain to use without some Pfunc shenanigans, like this:

Pdef(\b, Pbind(\dur, 0.25, \degree, Pseq((0..7), inf), \lag, 0.125 / Pfunc{ thisThread.clock.tempo}) <> midi).play;
// instead of just writing:
Pdef(\b, Pbind(\dur, 0.25, \degree, Pseq((0..7), inf), \timingOffset, 0.125) <> midi).play

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs.
Projects
None yet
Development

No branches or pull requests

4 participants