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 Senza Vibrato MW|2 Staccato Velocity 1 MW Shape|3 Staccato Velocity 2 MW Shape|4 Flutter Tongue MW|5 Short Velocity MW Shape|6 Secco Velocity MW Shape|7 Key Noises x Secco Velocity|8 Multiphonics + Undefined Tones Velocity|9 Key Noises Velocity|10 Senza Vibrato Velocity|11 Flutter Tongue Velocity|12 Senza Vibrato Velocity + MW inverted|13 Staccato 1 + Key Noises X Secco Velocity MW|14 Staccato 2 + Key Noises X Secco Velocity MW|15 Senza Vibrato + Flutter Tongue Velocity X MW|16 Triple Tongue 16T|17 Staccato Velocity|18 With Accent Velocity|19 Short Portato Velocity|20 Secco Velocity|21 Secco X Key Noises Velocity|22 Multiphonics MW|23 Crescendo|24 Portato Velocity|25 Vibrato MW|26 Vibrato Velocity|27 Vibrato Velocity + MW inverted|28 Flutter Tongue Velocity + MW inverted|29 Pseudo Flute Velocity + MW inverted|30 Pseudo Flute 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)
