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 MW Shape|3 Staccato Velocity MW Shape|4 Natural Vibrato piano|5 Cup Mute MW|6 Straight Mute MW|7 Harmon Mute MW|8 Plunger Velocity MW Shape|9 Plunger Velocity Release Trigger|10 Plunger o-c-o Velocity 8 sync|11 Undefined Tones Velocity MW Shape|12 Air + Vacuum Noises Velocity MW Shape|13 Mouthpiece Tones Velocity MW Shape|14 Valve Noises Velocity|15 Water Sounds Velocity|16 Water Tones Velocity MW Shape|17 Open Velocity + MW inverted|18 Open Velocity|19 Open Velocity Bell MW|20 Cup Mute Velocity|21 Harmon Mute Velocity|22 Straight Mute Velocity|23 Triple Tongue 16T|24 Open Velocity x MW Flutter Tongue|25 Staccato Velocity|26 With Accent Velocity|27 Natural Vibrato MW|28 Plunger Velocity|29 Undefined Tones Velocity|30 Air + Vacuum Noises Velocity|31 Mouthpiece Sounds MW|32 Water Tones Velocity|33 Flutter Tongue MW|34 Crescendo|35 Vibrato MW|36 Vibrato Velocity|37 Vibrato Velocity + MW inverted|38 Secco Velocity|39 Portato Velocity|40 Pseudo Horn Open Velocity + MW inverted|41 Pseudo Horn Staccato Velocity|42 Pseudo Piccolo Trumpet Open Velocity + MW inverted|43 Pseudo Piccolo Trumpet 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)
