-- Display a message in the console for debugging function Msg(value) if console then reaper.ShowConsoleMsg(tostring(value) .. "\n") end end console = true -- true/false: display debug messages in the console function toBits(num,bits) -- returns a table of bits, most significant first. bits = bits or math.max(1, select(2, math.frexp(num))) local t = {} -- will contain the bits for b = bits, 1, -1 do t[b] = math.fmod(num, 2) num = math.floor((num - t[b]) / 2) end return t end function bits(num) local t={} while num>0 do rest=num%2 table.insert(t,1,rest) num=(num-rest)/2 end return table.concat(t) end -- START retval_track, des_track = reaper.GetUserInputs("Send All Selected Tracks to Destination Track", 1, "Destination Track Number", "1") reaper.Main_OnCommand(40289, 0) -- Item: Unselect all items if retval_track then track_count = reaper.CountSelectedTracks( 0) for i = 1, track_count do track = reaper.GetSelectedTrack( 0, i -1) des_track_num = reaper.GetTrack( 0, des_track -1 ) track_item = reaper.GetTrackMediaItem( track, 0 ) reaper.SetMediaItemSelected( track_item, true ) item = reaper.GetSelectedMediaItem(0,0) take = reaper.GetActiveTake(item) retval, selected, muted, startppqpos, endppqpos, chan, pitch, vel = reaper.MIDI_GetNote( take, 1 ) reaper.CreateTrackSend( track, des_track_num ) --[[Kawa Code MIDI button(4bit), dest MIDI ch (5bit) ,src MIDI ch(5bit) 0001 00001 00001 -- result ( MIDI button ON , dest ch 1 , src ch 1) 0001 00111 00111 -- result ( MIDI button ON , dest ch 7 , src ch 7) 0000 00000 00000 -- result ( MIDI button OFF, dest ch ALL , src ch ALL) 0000 10000 10000 -- result ( MIDI button OFF, dest ch 16 , src ch 16) tonumber("00010000100001" , 2) ) -- get Decimal Number from Base 2 string --]] if chan+1 == 1 then bin_num = "00000000100001" end if chan+1 == 2 then bin_num = "00000001000010" end if chan+1 == 3 then bin_num = "00000001100011" end if chan+1 == 4 then bin_num = "00000010000100" end if chan+1 == 5 then bin_num = "00000010100101" end if chan+1 == 6 then bin_num = "00000011000110" end if chan+1 == 7 then bin_num = "00000011100111" end if chan+1 == 8 then bin_num = "00000100001000" end if chan+1 == 9 then bin_num = "00000100101001" end if chan+1 == 10 then bin_num = "00000101001010" end if chan+1 == 11 then bin_num = "00000101101011" end if chan+1 == 12 then bin_num = "00000110001100" end if chan+1 == 13 then bin_num = "00000110101101" end if chan+1 == 14 then bin_num = "00000111001110" end if chan+1 == 15 then bin_num = "00000111101111" end if chan+1 == 16 then bin_num = "00001000010000" end reaper.SetTrackSendInfo_Value( track, 0, 0, "I_MIDIFLAGS", tonumber(bin_num , 2) ) reaper.SetMediaItemSelected( track_item, false ) end end