Hello and Happy New Year to all;
I am trying to dynamically change \midinote. Is there any way to do it with a Tdef that regulates the changes of an array? or another more elegant way?
I tried to do it with the following code:
Tdef(\midinotes, {
loop{
[0,-5,-7,-12].do({ |i|
~midinotes = {([72,76,78,85] +.x [0.1,0.2]) * i.midiratio};
8.wait;
});
}
});
This does not work
~pb = Pbind(
\type, \midi,
\midiout, m,
\midicmd, \noteOn,
\midinote, ~freqs,
\dur, 2,
\amp, 1, // Pexprand(0.1,0.5)
);
* i.midiratio should be applied to frequencies, not to MIDI notes.
If you have MIDI notes and you want to transpose, simply add the number of semitones.
But your pattern uses ~freqs – and ~freqs is never assigned anywhere in this code example – so I would expect Pbind just to stop without playing anything.
I think I would keep the pitches expressed in midinotes throughout.
Then, you can’t simply write ~midinotes into your pattern because the variable reference will be resolved to its value once, at the time of creating the Pbind. Then it’s hardcoded forever (same as writing 1.0.rand in a SynthDef instead of Rand(0.0, 1.0)).
Pdefn is the easiest way to create a pattern/stream reference to something that can change.
(
Tdef(\midinotes, {
loop {
[0, -5, -7, -12].do { |i|
// here, `+ i` is what you were trying to do with midiratio
Pdefn(\midinotes, ([72, 76, 78, 85] + i) +.x [0.1,0.2]);
8.wait;
};
}
}).play(quant: 0);
~pb = Pbind(
\type, \midi,
\midiout, m,
\midicmd, \noteOn,
\midinote, Pdefn(\midinotes),
\dur, 2,
\amp, 0.1, // Pexprand(0.1,0.5)
).play(quant: 0);
)
Tdef’s defaultQuant doesn’t match Pbind’s default play quantization, so I found it necessary to specify quant.