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 Staccato Velocity MW Shape|3 Marcato Staccato Velocity MW Shape|4 Staccato + Marcato Velocity MW Shape|5 Bucket Mute MW|6 Straight Mute MW|7 Cup Mute closed-half-open MW|8 Cup Mute wo - closed MW|9 Plunger Velocity MW Shape|10 Plunger Velocity Release Trigger|11 Plunger wah Velocity MW Shape|12 Voice Breathing Velocity|13 Undefined Tones Velocity MW Shape|14 Plunger o-c-o Velocity 8 sync|15 Open Velocity + MW inverted|16 Open Velocity|17 Bucket Mute Velocity|18 Straight Mute Velocity|19 Cup Mute Velocity X MW|20 Open Velocity Bell MW|21 Triple Tongue 16T|22 Staccato + Marcato Velocity|23 With Accent Velocity|24 Plunger Velocity|25 Voice Breathing MW|26 Undefined Tones Velocity|27 Crescendo|28 Vibrato MW|29 Vibrato Velocity|30 Vibrato Velocity + MW inverted|31 Secco Velocity|32 Portato Velocity|33 Flutter Tongue MW - Foot|34 Flutter Tongue Velocity - Foot|35 Pseudo Tuba Open Velocity + MW inverted|36 Pseudo Tuba Staccato + Marcato Velocity|37 Pseudo Horn Open Velocity + MW inverted|38 Pseudo Horn Staccato + Marcato 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)
