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 Open MW|2 Flutter Tongue Velocity|3 Staccato Velocity MW Shape|4 Cuivre Brassy Velocity|5 Mute MW|6 Stopped MW|7 Stopped sfz MW Switch|8 Valve Noises Velocity|9 Air Noises Velocity MW Shape CC4|10 Undefined Tones Velocity MW Shape|11 Metal Noises Velocity|12 Undefined Fast Tones Velocity MW Shape|13 Open Velocity + MW inverted|14 Open Velocity|15 Open Velocity Bell MW|16 Open Velocity x MW Flutter Tongue|17 Glissando Open Velocity|18 Glissando Mute Velocity|19 Mute Velocity|20 Stopped Velocity|21 Triple Tongue 16T|22 Mute Velocity Bell MW|23 Stopped Velocity Bell MW|24 Staccato Velocity|25 Air Noises Velocity|26 Undefined Tones Velocity|27 Undefined Fast Tones Velocity|28 Stopped sfz Velocity|29 With Accent Velocity|30 Cuivrer Brassy MW|31 Flutter Tongue MW|32 Glissando Open MW|33 Glissando Mute MW|34 Crescendo|35 Vibrato MW|36 Vibrato Velocity|37 Vibrato Velocity + MW inverted|38 Secco Velocity|39 Portato Velocity|40 Pseudo Trumpet Open Velocity + MW inverted|41 Pseudo Trumpet Staccato Velocity|42 Pseudo Tuba Open Velocity + MW inverted|43 Pseudo Tuba 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)
