Which types of conditional statements should I use?

Ok I’m going to do my best to explain here what I’m trying to do with a script and hopefully some of the more experienced users can point me in the right direction. I’m not very experienced with code/scripting but I understand some of the basics and have read through a lot of the documentation.

I’m a keyboardist in a three-piece band where I play bass parts in my left hand and keys parts in my right hand with midi splits going to different plugins. Basically I want to write a script where my left hand midi block hitting certain notes will turn on/off a specific midi note on function in my right hand midi block.

Ex.:
Once I hit an F#1 in my left hand I want every note I play in my right hand to also have an F#2 that plays simultaneously with any note in that midi block.

Once I hit an E1 in my in left hand I want every note I play in my right hand to have a simultaneous E2 (but not the F#2 from the previous chord) etc.

Essentially it’s like my left hand is determining which argument to follow for the right hand midi block. Not sure if I should be using For, While, Select, etc. If anyone can point me in the right direction I’d really appreciate it!

I don’t think you need a script for this. Create another midi block that covers the same range as the bass part. Set that midi block to transpose up an octave. Send that midi out to the right hand plugin.

Sorry I think I was unclear, I don’t want the left hand part to go to the right hand plugin. The right hand part is playing different rhythms from the left hand and I want a specific midi note on message to be sent with every note on from the right hand (in addition to each note the right hand is playing already.

Try this.
PlayLeftNote.gig (24.4 KB)

And this is the used Rackspace Script

//$<AutoDeclare>
// DO NOT EDIT THIS SECTION MANUALLY
Var
   MLeft  : MidiInBlock
   MRight : MidiInBlock
   v_played_note : NoteMessage
   v_play : boolean
//$</AutoDeclare>


on NoteEvent (m : NoteMessage) matching [C-2..B2] from MLeft
 if IsNoteOn(m) then
  v_played_note = MakeNoteMessageEx(GetNoteNumber(m), 
                                    GetVelocity(m),
                                    GetChannel(m))
  v_play = true                                    
 else          
  v_play = false
 end
 SendNow(MLeft, m)
end 

on NoteEvent(m : NoteMessage) from MRight
 SendNow(MRight, m)
 if v_play == true then
  SendNow(MRight, v_played_note) 
 end 
end

I know it is not perfect, maybe hanging notes, wrong MIDI channel, unwanted velocity etc.
But it shows how it could work for you.

1 Like

Thanks for taking the time to write that up! I couldn’t really tell all that was actually happening when I tried compiling the code after changing some of the values, but I think this will be a good starting point for me to troubleshoot from. The scripting logic/syntax is starting to make sense to me (I think).

Here a more better version of the script,
all notes played with the left hand are play also with the right.

//$<AutoDeclare>
// DO NOT EDIT THIS SECTION MANUALLY
Var
   MLeft  : MidiInBlock
   MRight : MidiInBlock
   nt     : NoteTracker
   
   nn     : Integer Array
   i      : Integer
//$</AutoDeclareSize()
initialization
 NoteTracker_Clear(nt)
end

on Activate
 NoteTracker_Clear(nt)
end 

on NoteEvent (m : NoteMessage) matching [C-2..C8] from MLeft
 if IsNoteOn(m) then
  NoteTracker_GotNoteOn(nt, GetNoteNumber(m))
 else          
  NoteTracker_GotNoteOff(nt, GetNoteNumber(m))
 end
 SendNow(MLeft, m)
end 

on NoteEvent(m : NoteMessage) from MRight
 SendNow(MRight, m)
 nn = NoteTracker_GetHeldNotes(nt)

 For i=0; i<Size(nn); i=i+1 Do
  SendNow(MRight, MakeNoteMessageEx(nn[i], GetVelocity(m), GetChannel(m)))
 End
 
end
1 Like

And with this change

And this script, you can define the transpose of the additional played notes in the MIDI In Block

//$<AutoDeclare>
// DO NOT EDIT THIS SECTION MANUALLY
Var
   MLeft  : MidiInBlock
   MRight : MidiInBlock
   MRightHelper : MidiInBlock
   nt     : NoteTracker
   
   nn     : Integer Array
   i      : Integer
//$</AutoDeclareSize()
initialization
 NoteTracker_Clear(nt)
end

on Activate
 NoteTracker_Clear(nt)
end 

on NoteEvent (m : NoteMessage) matching [C-2..C8] from MLeft
 if IsNoteOn(m) then
  NoteTracker_GotNoteOn(nt, GetNoteNumber(m))
 else          
  NoteTracker_GotNoteOff(nt, GetNoteNumber(m))
 end
 SendNow(MLeft, m)
end 

on NoteEvent(m : NoteMessage) from MRight
 SendNow(MRight, m)
 nn = NoteTracker_GetHeldNotes(nt)

 For i=0; i<Size(nn); i=i+1 Do
  SendNowRespectingParameters(MRightHelper, MakeNoteMessageEx(nn[i], GetVelocity(m), GetChannel(m)))
 End
 
end
3 Likes

Wow, thank you for all of that @pianopaul! Can’t wait to dig in. I think between the three you posted I’m going to be able to do exactly what I was trying to explain in the original post. Skimming through it, the third script might even be perfect as is!

As an aside, really enjoying getting into GP4 over the past week. Obviously the software itself is great and very intuitive once you get into it, but the community here is also extremely helpful and friendly. Definitely going to be recommending more of my musician friends get into Gig Performer.

6 Likes