|
|
|
06-15-2018, 01:44 PM
|
#1
|
Human being with feelings
Join Date: Jan 2011
Posts: 610
|
Need action to change Reaper input
I have been trying to get a macro together to accomplish one of the most common multiple tasks I encounter in Reaper and I have hit a wall because it seems that there is no way to change the track input from the default audio to midi other than manually. Can this be right? Using the SWS action that changes the midi channel will only work once you have set the input to midi, and so far I have not been able to figure out how to do that with an action.
I'm hoping there's something obvious I have overlooked.
Anybody?
|
|
|
06-15-2018, 01:56 PM
|
#2
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
I don't see any actions for assigning inputs. Scripts can do it, though.
|
|
|
06-15-2018, 04:03 PM
|
#3
|
Human being with feelings
Join Date: Jan 2011
Posts: 610
|
Quote:
Originally Posted by Lokasenna
Scripts can do it, though.
|
Easy for you to say, LOL!
|
|
|
06-15-2018, 06:37 PM
|
#4
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
You're right, it is easy.
Tyrannocaster - Set selected tracks to MIDI input.lua
It uses channel 0 (all channels), but you can edit the first line if you need something else.
Last edited by Lokasenna; 06-16-2018 at 08:44 AM.
|
|
|
06-16-2018, 06:55 AM
|
#5
|
Human being with feelings
Join Date: Jan 2011
Posts: 610
|
Quote:
Originally Posted by Lokasenna
|
Wow, that is neat; thanks! Now I have to remember where to put it and how to install it - I hardly ever use scripts, although I have the SWS extension installed. I am assuming that an SWS script can be used in a macro just like a regular Reaper action.
|
|
|
06-16-2018, 07:06 AM
|
#6
|
Human being with feelings
Join Date: Jan 2011
Posts: 610
|
Which line are you calling the "first line"? Because the actual first line is just the doctype stuff. I don't know anything about scripting so it's hard for me to find what you are referring to. At least I got it installed, though. :-)
EDIT: when I run the resulting macro with your script in it I get this error: "Tyrannocaster - Set track to MIDI input.lua:1:unexpected symbol near '<'
|
|
|
06-16-2018, 07:52 AM
|
#7
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
- Scripts don't necessarily need SWS - only if they're using functions provided by SWS, which this one doesn't.
- Sorry, I was referring to line 3: local midi_channel = 0.
- There's nothing in the script that could cause the error you're seeing. It's referring to a < on line 1, which isn't there at all unless you accidentally typed something in while saving it.
|
|
|
06-16-2018, 08:31 AM
|
#8
|
Human being with feelings
Join Date: Jan 2011
Posts: 610
|
Quote:
Originally Posted by Lokasenna
- Scripts don't necessarily need SWS - only if they're using functions provided by SWS, which this one doesn't.
- Sorry, I was referring to line 3: local midi_channel = 0.
- There's nothing in the script that could cause the error you're seeing. It's referring to a < on line 1, which isn't there at all unless you accidentally typed something in while saving it.
|
Then Drop Box must mess it up - there's nothing like what you described anywhere near the beginning of this thing. Take a look:
<!DOCTYPE html><html xml:lang="en" class="maestro" xmlns="http://www.w4.org/1999/xhtml"><head><script nonce="cuJNK/RVcOihOfHvWeaB">window._goch_ = {};window.addEventListener('click', function(event) { 'use strict'; for (var elm = event.target; elm; elm = elm.parentElement) { if (elm.id && window._goch_.hasOwnProperty(elm.id) && window._goch_[elm.id].call(elm, event) === false) { event.preventDefault(); } }}, true);window._csp_external_script_nonce = "2OyjzMuyThjvUz1W0ax/"</script><link href="https://cfl.dropboxstatic.com/static/images/favicon-vflUeLeeY.ico" rel="shortcut icon" /><script type="text/javascript" nonce="cuJNK/RVcOihOfHvWeaB">window.ST=+new Date();</script><link href="https://cfl.dropboxstatic.com/static/images/logo_catalog/dropbox_webclip_60_m1-vflgZE2qv.png" rel="apple-touch-icon" /><link href="https://cfl.dropboxstatic.com/static/images/logo_catalog/dropbox_webclip_76_m1-vflB_aAVn.png" rel="apple-touch-icon" sizes="76x76" /><link href="https://cfl.dropboxstatic.com/static/images/logo_catalog/dropbox_webclip_120_m1-vflmwkfBS.png" rel="apple-touch-icon" sizes="120x120" /><link href="https://
and so on, for about twenty pages. Somehow, I don't think that's what you had in mind.
That's what happens if I try to read it on my Mac with a text editor even after supposedly converting it to Windows format, but it's equally bad on my PC (which is not online, or I would be typing on it now).
What do I have to do to get the correctly formatted script from Drop Box?
|
|
|
06-16-2018, 08:45 AM
|
#9
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Ah, I slipped an extra ] into the BBCode by accident. Fixed, should download the Lua file directly now.
|
|
|
06-16-2018, 09:06 AM
|
#10
|
Human being with feelings
Join Date: Jan 2011
Posts: 610
|
Quote:
Originally Posted by Lokasenna
Ah, I slipped an extra ] into the BBCode by accident. Fixed, should download the Lua file directly now.
|
Sorry to be so troublesome, but something is seriously off here. Surely this file isn't supposed to be that big: 340K for a simple script? It's still just as unreadable as it was before. And I still get the same error as before.
|
|
|
06-16-2018, 09:12 AM
|
#11
|
Human being with feelings
Join Date: Jan 2011
Posts: 610
|
The problem was the link. I rewrote it and got to dropbox without downloading all that javascript. But it's still funky, because although I can see the script itself, there's no download option. This is so weird; I've used Dropbox before without anything like this.
Anyway, here is the script:
-- Set the selected track(s) to MIDI input
local midi_channel = 0
-- Get the number of selected tracks
local num_tracks = reaper.CountSelectedTracks()
-- If we don't have any selected tracks, abort the script
if num_tracks == 0 then
return
end
-- Keeps Reaper's undo history tidy
reaper.Undo_BeginBlock()
-- The selected tracks are numbered from 0
for i = 0, num_tracks - 1 do
-- Get the track's info
local track = reaper.GetSelectedTrack(0, i)
--[[
reaper.SetMediaTrackInfo_Value( tr, parmname, newvalue )
I_RECINPUT : int * : record input.
<0 = no input,
0..n = mono hardware input,
512+n = rearoute input,
1024 set for stereo input pair.
4096 set for MIDI input,
if set then low 5 bits represent channel (0=all, 1-16=only chan),
then next 5 bits represent physical input (63=all, 62=VKB)
]]--
reaper.SetMediaTrackInfo_Value(track, "I_RECINPUT", 4096 + 32 + midi_channel)
end
reaper.Undo_EndBlock("Set the selected track(s) to MIDI input", 1)
--------------
If you tell me how to turn this into an action I'll just do it on my end.
Thanks. And sorry about all the trouble. And now, Dropbox is telling me I need to have an account to download - WTF? I'm not going to create yet another one-shot account. Don't mean to rant, but I am sick of sites that do this.
|
|
|
06-16-2018, 09:24 AM
|
#12
|
Human being with feelings
Join Date: Jan 2011
Posts: 610
|
EDIT:
What a hassle, but I finally got it, and it works. But wow - I downloaded it with my tablet instead of with my desktop browser, which worked. (Dropbox doesn't like my Mac's Firefox, I guess.) then, when I tried to copy it from my tablet to my PC, the PC couldn't see the file on the tablet, although everything else in the downloads folder showed up! I finally ended up emailing it to myself from my tablet, saving the attachment on the Mac, then transferring it to the PC on a flash drive, where I replaced the messed up one and Reaper immediately ran it without trouble. As you said, it sets it to all channels, but I know how to change that, and in fact, that could be useful so for now I'll leave it as it is.
Again, sorry about all the confusion, which I find really perplexing; for some reason, this file just did not want to come to my house! :0(
Last edited by Tyrannocaster; 06-16-2018 at 09:36 AM.
|
|
|
06-16-2018, 09:50 AM
|
#13
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Blame Dropbox. I hate them, but all my files are there.
Left-clicking the link (right-click won't work because, again, Dropbox sucks) in my post here brings up a Save As dialog and it saves the original file just fine.
Weird. :/
|
|
|
06-16-2018, 10:10 AM
|
#14
|
Human being with feelings
Join Date: Jan 2011
Posts: 610
|
Quote:
Originally Posted by Lokasenna
Blame Dropbox. I hate them, but all my files are there.
Left-clicking the link (right-click won't work because, again, Dropbox sucks) in my post here brings up a Save As dialog and it saves the original file just fine.
Weird. :/
|
Isn't it, though. But the best part is that it works - with the rest of the macro I already had, now all I have to do is click once on the toolbar and any selected track is armed, monitor is on, and the midi input is available. This is great.
Thanks again!
|
|
|
09-18-2019, 08:23 AM
|
#15
|
Human being with feelings
Join Date: Dec 2012
Location: Germany
Posts: 3,039
|
Code:
reaper.SetMediaTrackInfo_Value(track, "I_RECINPUT", 4096 + 32 + midi_channel)
<0 = no input
0..n = mono hardware input
512+n = rearoute input
1024 = stereo input pair
4096 = MIDI input, if set then low 5 bits represent channel (0=all, 1-16=only chan),
then next 5 bits represent physical input (63=all, 62=VKB)
I can't seem to figure out how this actually works consistently. I'd like to set a desired MIDI input device via a script (toolbar button). I modified Lokasenna's script and it seems to work for some MIDI input devices but not for all because the numbers based on 4096 seem to be inconsistent.
When I save a simple project with only a single MIDI track set to my first MIDI input device ("VMidi 1" from CopperLan), I can find this entry in the rpp file:
REC 0 4736 0 0 0 0 0
Looking up the device's ID in MIDI devices prefs reveals that its ID is 20. 4096 + 20 x 32 equals 4736. I put this value into the script and it works. The formula also works for a few other MIDI input devices. However, if I wanna select my MIDI input "VMidi 8" which has the ID 55, the value I'm getting is 4096 + 55 x 32 = 5856 and it actually works in the script but when I save a project file incl. the MIDI track set to this MIDI input device, I find this entry:
REC 0 5920 0 0 0 0 0
However, using this entry in the script does not work in return. I'm a bit confused.
btw, what does "VKB" mean?
.
|
|
|
09-18-2019, 09:18 AM
|
#16
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
That's Reaper's built-in Virtual Keyboard - it's in the View menu.
|
|
|
09-19-2019, 04:39 AM
|
#17
|
Human being with feelings
Join Date: Dec 2012
Location: Germany
Posts: 3,039
|
Quote:
Originally Posted by Lokasenna
That's Reaper's built-in Virtual Keyboard - it's in the View menu.
|
thanks!
Can anyone explain the logic behind defining specific MIDI devices? Am I making false assumptions concerning the formula 4096 + ID x 32 which doesn't seem to work in every case?
.
|
|
|
09-19-2019, 06:07 AM
|
#18
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
You are - in the original code, 32 is the input it's using, so you don't want to add that. I think you want:
Code:
input = 17 + input_number
channel = 0 // 0 = all, 1-16 = channel numbers
i_recinput = 4096 + input + channel
|
|
|
09-19-2019, 06:51 AM
|
#19
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
|
Quote:
Originally Posted by SonicAxiom
Can anyone explain the logic behind defining specific MIDI devices?
|
No I can't, but using your post and post by Mordi I came up with this, the REC number in the RPP is the same when I use my MIDI devices ID (0 or 1), but not the same when using all(63) or VKB(62). But it does seem to work as expected.
Code:
local channel = 1 -- 0 = all channels, 1-16 = channel #.
local input = 1 -- 63=all, 62=VKB, (my MIDI Devices ID, 0=UM_One, 1=UMC204HD)
local flags = 4096 | channel | (input << 5)
for i = 0, reaper.CountSelectedTracks(0) - 1 do
local track = reaper.GetSelectedTrack(0, i)
reaper.SetMediaTrackInfo_Value(track, "I_RECINPUT", flags)
end
|
|
|
09-21-2019, 03:27 PM
|
#20
|
Human being with feelings
Join Date: Dec 2012
Location: Germany
Posts: 3,039
|
thank you Loka and Edge!
I got it working using the string "4096 | midi_channel | input << 5" with "input" being the ID of the desired MIDI interface. But what does "<< 5" mean here? And what do the vertical separators stand for?
.
Last edited by SonicAxiom; 11-26-2019 at 03:01 PM.
|
|
|
09-21-2019, 04:34 PM
|
#21
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
|
http://www.lua.org/manual/5.3/manual.html#3.4.2
3.4.2 – Bitwise Operators
Lua supports the following bitwise operators:
&: bitwise AND
|: bitwise OR
~: bitwise exclusive OR
>>: right shift
<<: left shift
~: unary bitwise NOT
|
|
|
09-21-2019, 07:26 PM
|
#22
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
In binary, OR ( | ) is analogous to addition. A left shift ( << ) means "add zeroes onto the end", giving you the 5 bits of "padding" I was getting above by adding 17 (which maybe should have been 16... not sure...).
|
|
|
09-22-2019, 03:11 PM
|
#23
|
Human being with feelings
Join Date: Dec 2012
Location: Germany
Posts: 3,039
|
thank you both for the explanations!
.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 04:09 AM.
|