Transposition for MIDI Keyboard

Hey there

I have the following SynthDef:

(
SynthDef(\saw, {

	arg freq=440,out=0;

	var snd, fft, key, feedb;

	feedb = LocalIn.ar(2);

	snd = LFSaw.ar(freq+LFDNoise3.ar(3,0.7),mul:1).tanh;

	snd = snd+(feedb*0.5);

	LocalOut.ar(snd);

	snd = FreeVerb.ar(snd,0.4,1);

	fft = FFT(LocalBuf(4096), snd);

	key = KeyTrack.kr(fft);

	Out.ar(out,snd);

}).add
)

And I want to use this with a MIDI Keyboard:

MIDIClient.init;
MIDIIn.connectAll;

(
var notes, on, off;

notes = Array.newClear(128); 

on = MIDIFunc.noteOn({ arg veloc, num, chan, src;
	notes[num] = Synth(\saw, [\freq, num.midicps]);
});

off = MIDIFunc.noteOff({ arg veloc, num, chan, src;
    notes[num].release;
});

)

I would like to transpose this Synth one semitone higher. I tried something like “num=num+1” or “(num+1).midicps” but this isn’t doing what I am looking for and I don’t have any ideas left.

Thanks!

num.midicps + offset number?

Maybe I am doing something wrong. If I try what you suggest it starts to sound a bit more cluster-like on my device. It’s not what I am looking for in this situation.

That’s the right basic idea, but there’s some missing detail in your question:

  • Where did you put the num = num + 1 in the code?

  • What did it do that isn’t what you wanted?

That wouldn’t work because midicps outputs Hz, while the offset number is in semitones.

hjh

That’s the right basic idea, but there’s some missing detail in your question:

  • Where did you put the num = num + 1 in the code?
  • What did it do that isn’t what you wanted?

Now it works when I write “[\freq, (num+1).midicps]);”

I have no clue why it is behaving different now, but I don’t think I am doing it in a different way than yesterday. Anyway…

“That wouldn’t work because midicps outputs Hz, while the offset number is in semitones.”

Thank you, that is pretty convenient to know.

tip: you can use .midiratio to multiply hz values like so:

Synth(\default,[\freq,440]) // a
Synth(\default,[\freq,1.midiratio*440]) // one semitone higher
Synth(\default,[\freq,440 / (1.midiratio) ]) // one semitone lower