GrainBuf in a MIDIdef: it works, but it doesn't

Hi!
I’m trying to make a MIDIdef using GrainBuff as a synth.
But the problem I’m facing is more technical than I can understand why.
Generaly, I’m working on making a simple midi yet when I’m running it the Post window shows:

-> MIDIdef(off, noteOff, nil, nil, nil)

while the Code is this:

(
Buffer.freeAll;
~buf1 = Buffer.read(s, "C:/Users/user/Desktop/September programming 2/Samples/GtrMono1.wav");
)
(
SynthDef(\GrainNotes,
	{
		arg gateE = 1,freqT = 20, phaseT = 0, mulT = 0, rt = 1, cfH = 1,
		durG = 0.1, rateG = 60, pos = 0.1, pan = 0, out = 0, ampGrainNotes = 0;
		var sig, env;

		env = Env.adsr(releaseTime: rt);
		env = EnvGen.kr(env, gateE, doneAction: 2);

		sig =  GrainBuf.ar(
			numChannels: 2,
			trigger: Impulse.ar(
				freq: freqT,
				phase: phaseT,
				mul: mulT),
			dur: durG/*{Rand(0.001,3)}*/,
			sndbuf: ~buf1,
			rate: rateG,
			pos: 0.1,
			interp: 2,
			pan: LFNoise0.kr(),
			envbufnum: -1,);
		sig = HPF.ar(sig, cfH.clip(20, 8000));

		sig = sig * env * ampGrainNotes;

		Out.ar(out,sig);

}).add;
)
(
MIDIdef.noteOn(\on, {  

	arg vel, nn;
	[vel, nn].postln;

	~notes[nn] = Synth(\GrainNotes, [
		\rateG, nn.midicps,
		\ampGrainNotes, vel.linexp(0, 127, 0.01, 1),
		\gateE, 1,
		\cfH, ~cutOff,\rt,~rtl])

}).permanent_(true);

MIDIdef.noteOff(\off, {

	arg vel, nn;
	~notes[nn].set(\gateE, 0);
	~notes[nn] = nil;

}).permanent_(true);
)

That’s correct and expected behavior.

Your code block is technically called an Expression Sequence. The result of an expression sequence is only the result of the last expression. But all of the expressions executed and created their objects. Only the last one is posted, but they all did their work.

Just for the sake of checking, since your code block doesn’t show it, did you do MIDIClient.init? MIDI won’t respond without doing that once first.

hjh