Midi sequence playback

Hello, I tried out your “Time ot of mind” code. But I don’t know what Iam doin wrong. Allways when i try to compile it I get the following message: Rackspace (Rackspace) - Semantic error in “Main”: Line 2, Col 4: Variable not found: trackCount

Initialization
trackCount := MidiSequence_LoadMidiFile(cs, “/Volumes/mds/seq1.mid”)
Print(trackCount)
MidiSequence_Quantize(cs, 2)
MidiSequence_MapOutputChannel(cs, 2, 4)
end

On NoteEvent(m : NoteMessage) Matching [C0…D0], B-1 from Keyboard
var

notes : MidiMessage Array
aNote : MidiMessage
index : integer
trackIndex : integer
if IsNoteOn(m)
then

    if MidiSequence_EndOfSong(cs) or m.GetNoteNumber() == B-1
        then MidiSequence_ResetToStart(cs)
    end

    MidiSequence_CollectEventsNow(cs);

    notes = MidiSequence_GetCurrentEvents(cs, 3) // Lead synth
    //Print(Size(notes))
    for index = 0; index < Size(notes); index = index + 1 do
       aNote = notes (index)
       //Print{aNote)
       LeadSynth.SendNow(aNote)
    end
 end

End

On NoteEvent(m : NoteMessage) Matching A-1 from Keyboard
MidiSequence_ResetToStart(cs)
AllNotesOff (LeadSynth)
end

I never scripted before I am total new to that. Perhaps you can help me?
Thx

By the way i was really impressed by the possibilities your script could bring into a live performance without click…

1 Like

var trackCount : Integer

Initialization
trackCount = MidiSequence_LoadMidiFile(cs, “/Volumes/mds/seq1.mid”)
Print(trackCount)

write those " instead of “ - there is a difference, believe me ;-)…

This script looked very interesting. I tried re-creating it with the updates and also got a semantic error on the line after initialization. Looks like an undeclared object?

Look in the doc what variable type is “cs” and declare it as a global variable in the “var” section at the beginning of the script.

The problem is that the original graphic that @pianopaul posted is missing the declarations at the top

I couldn’t manage it. :frowning: Is it possible to post the missing top of the script too? Or is it possible to get a user example gig file. Thx a lot

The complete script is actually here…

Thx…I tried… now I get a semantic error at aNote in Line 31. Identifier is not a function: notes
???

Will fix it tonight, will come back to you in some hours.

I give it a try. Thx

What is the complete message? And please paste in lines 30-32 as well so we can see it in context

Found the culprit

This
aNote := notes(index)

Must be changed to this
aNote = notes[index]

And at the beginning you have to add this:

LeadSynth : MidiInBlock

So the complete script looks this way

var Keyboard : MidiInBlock
    LeadSynth : MidiInBlock
    trackCount : Integer
    cs : MidiSequence
    
initialization
 trackCount := MidiSequence_LoadMidiFile(cs, "/Volumes/mds/seq1.mid")
 Print(trackCount)
 MidiSequence_Quantize(cs, 2)
 MidiSequence_MapOutputChannel(cs, 2, 4)
end

on NoteEvent(m : NoteMessage) matching [C0..D0], B-1 from Keyboard
var
   
   notes : MidiMessage Array
   aNote : MidiMessage
   index : integer  
   trackIndex : integer
   if IsNoteOn(m) 
     then
   
     if MidiSequence_EndOfSong(cs) or m.GetNoteNumber() == B-1
        then MidiSequence_ResetToStart(cs)
     end
 
     MidiSequence_CollectEventsNow(cs);
     
     notes = MidiSequence_GetCurrentEvents(cs, 3)
     
     for index =0; index < Size(notes); index = index + 1 do
        aNote = notes[index]
        
        LeadSynth.SendNow(aNote)
     end   
     
  end
 
end
1 Like

Thank you. Now the script compiles. How has the midi sequence has to be set up? What track number is meant? I still try to understand the code… there’s cs, 2,4 and 3
image
sorry for beein’ such a noob

Thx for help. Now it works. But it still not plays the midifile…How has the midifile to be setup…
image

How many tracks did you create in your MIDI-File?

only one

it needs 3 or?

replace 3 by 1 and try again.