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