selected = false
muted = false
midiChan = 0

gfx.init("Xsample",1,1)

gfx.x = gfx.mouse_x
gfx.y = gfx.mouse_y

input = gfx.showmenu("1 Vibrato MW|2 Senza Vibrato MW|3 Staccato Velocity 1 MW Shape|4 Staccato Velocity 2 MW Shape|5 Air - Slap Tongue RS|6 Crow On Reed Velocity MW Shape|7 Helicopter Velocity|8 Key Noises Velocity|9 Multiphonics Velocity|10 Various Noises Velocity|11 Air Noises Velocity CC4|12 Undefined Tones Velocity MW Shape|13 Vibrato Velocity|14 Senza Vibrato Velocity|15 Vibrato Velocity + MW inverted|16 Senza Vibrato Velocity + MW inverted|17 Vibrato - Senza Vibrato Velocity X MW|18 Vibrato + Senza Vibrato MW 2 dimensional X CC2|19 Triple Tongue 16T|20 Staccato Velocity|21 Crow On Reed Velocity|22 Crow On Reed Tones MW|23 Multiphonics MW|24 Air Noises MW|25 Undefined Tones Velocity|26 With Accent Velocity|27 Crescendo|28 Portato Velocity|29 Secco Velocity|30 Vibrato to Senza Vibrato Velocity|31 Senza Vibrato to Vibrato Velocity|32 Flutter Tongue MW - Foot|33 Flutter Tongue Velocity - Foot|34 Pseudo Sub Velocity + MW inverted|35 Pseudo Sub Staccato Velocity|36 Pseudo Bassoon Velocity + MW inverted|37 Pseudo Bassoon Staccato Velocity||")
if input >= 0 then 

function main() 
  take = reaper.MIDIEditor_GetTake(reaper.MIDIEditor_GetActive())
  if take == nil then return end
  item = reaper.GetMediaItemTake_Item(take)
  pos = reaper.GetCursorPosition() 
  ppq = reaper.MIDI_GetPPQPosFromProjTime(take, pos)
  
  MSB = 0
  LSB = 0
  PC  = 0
  
  if input ~= 0 then
  
  reaper.MIDI_InsertCC(
    take, 
    selected,
    muted,
    ppq,
    0xB0,-- midi CC
    midiChan,
    0, -- controller #0: Bank Select MSB
    input-1 -- MSB value
  )
  reaper.MIDI_InsertCC(
    take, 
    selected,
    muted,
    ppq,
    0xB0,-- midi CC
    midiChan,
    32, -- controller #32: Bank Select LSB
    0 -- LSB value
  )
  reaper.MIDI_InsertCC(
    take, 
    selected,
    muted,
    ppq,
    0xC0,-- Program Change
    midiChan,
    PC, -- program change value
    0
  )
  end
  reaper.UpdateItemInProject(item)   
end
end

script_title = "Xsample Acoustic Instruments"
reaper.Undo_BeginBlock()
main()
reaper.Undo_EndBlock(script_title, 0)
