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  MW Shape|3 Flutter Tongue MW|4 Crescendo|5 Accent Velocity|6 Key Noises Velocity|7 Multiphonics + Undefined Tones|8 Slides Down Velocity|9 Slides Up Velocity|10 Senza Vibrato Velocity|11 Senza Vibrato Velocity + MW inverted|12 Flutter Tongue Velocity|13 Senza Vibrato + Flutter Tongue Velocity X MW|14 Triple Tongue 16T|15 Staccato Velocity|16 Accent Sustain Velocity|17 Multiphonics MW|18 Air Noise MW|19 Vibrato MW|20 Vibrato Velocity|21 Vibrato Velocity + MW inverted|22 Secco Velocity|23 Portato Velocity|24 Flutter Tongue Velocity + MW inverted|25 Pseudo Bass Velocity + MW inverted|26 Pseudo Bass Staccato Velocity|27 Pseudo Piccolo Velocity + MW inverted|28 Pseudo Piccolo 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)
