A thread for quick ReaScript questions (not worth opening a dedicated thread for).
Thank you...
I'll try this out because I am looking for an answer to this related to using Lua.
I am programming a function to 'push' or 'save' the user's current keystrokes into persistent variables from the 'reaper-kb.ini' file.
Correspondingly, I have programmed a function to 'pop' or 'recall' the user's current keystrokes and place them back into the 'reaper-kb.ini' file.
This is being done so that I can temporarily reprogram some keystrokes to be different functions for a short while... then later after the need for the re-assigned keystrokes is over, I can return those keystrokes back to their originally chosen functions/scripts.
My question is this...
How can I 'force' Reaper to ReLoad the keystrokes in the 'reaper-kb.ini' file without having to close and re-open Reaper?
Thank you.
Larry
Last edited by LarrySeyer; 07-24-2020 at 03:43 PM.
How do I locate a folder/file in media explorer? I don't mean to "OPEN" something with MX, which is easy to do with reaper.OpenMediaExplorer. What I want is, for example, here is a folder "E:\REAPER\Scripts", then I need MX to open "E:\REAPER" then "FOCUS" on folder Scripts.
Use reaper.OpenMediaExplorer and give it a path instead of a file.
Set play to false.
Ah perfect! Thanks.
Little update: The path should be "E:\REAPER\Scripts", instead of "E:\REAPER\Scripts\". If the last character is a slash, OpenMediaExplorer will open it no matter what flag you give it.
some way to get which intervals or pitch classes are in a scale ?
reaper.MIDI_GetScale
can get it's name and the root and a number like 2741. I would like some action to get more espesific info about the scale in MIDI editor
EDIT: I was suspicious about that number, if i put it in binary it gives me the scale, cool
Last edited by daniellumertz; 08-05-2020 at 10:41 PM.
some way to get which intervals or pitch classes are in a scale ?
reaper.MIDI_GetScale
can get it's name and the root and a number like 2741. I would like some action to get more espesific info about the scale in MIDI editor
EDIT: I was suspicious about that number, if i put it in binary it gives me the scale, cool
Thanks for that message I noticed that something is wrong because 2741 I get from major not from Lydian. yet it in binary is the Lydian as you said. What is going on???? some reaper error?
Lydian - 2773 - 101011010101 - The major scale
Major - 2741 - 101010110101 - Lydian Scale
Mixolydian - 1717 -11010110101 - The Locrian Scale
Dorian - 1709 - 11010101101 - Phrygian Scale
Minor - 1453 - 10110101101 - Minor Scale ( But it is missing one number)
Phrygian - 1451 - 10110101011 - Dorian scale
Locrian - 1387 - 10101101011 -Mixolidian Scale
Scale - Number get - In binary - Which scale it corresponds
I think reaper is right by this site https://ianring.com/musictheory/scales/
don't know how I can convert for exemple 2741 in a Major
even in the site
2741 101010110101 major scale
but this binary shouldn't be the lydian?
I think I missing something.....
Last edited by daniellumertz; 08-06-2020 at 03:42 PM.
Can you explain how to get and set it properly? Would like to add this information to my ReaperApidocs. Could be handy for many but I never use Midi to know what I am doing
Can you explain how to get and set it properly? Would like to add this information to my ReaperApidocs. Could be handy for many but I never use Midi to know what I am doing
Hi mespotine, I think it would be very cool to add.
but reaper and this site (ianring.com) are using 2741 for major. I can't understand why. The only logical thing I can think is something is switched.... I sended an email to ianring
EDIT:
ok this video show more in depth how the number is get than what is written
also the missing part is explained how they are converted from binary to decimals. Now it makes sense, but Idk how one can convert an number back to binary the way they are doing...
Last edited by daniellumertz; 08-06-2020 at 05:59 PM.
Ok, sorry my blablabla in the lasts posts, I understood how it works now, I sugest to see the video I posted to understand the system.
this code transform the number reaper uses for scales in a binary string
like
if scale = 2741
scale_in_string = 101011010101
Code:
scale = 2741
scale_in_binary = {}
i = 0
while scale ~= 0 do
rest = scale % 2
scale = scale / 2
scale = math.floor(scale)
i = i + 1 --count of how many times it divided
scale_in_binary[i] = (rest) --store the rest in scale_in_binary
end
scale_in_string = table.concat(scale_in_binary)
Overlap and Crossfade items when splitting Length
------****------
Other question any way to know which lane an Item is? ( I open a topic for that showing how I'm doing but if there is an very simple way I would like to know because mine is NOT 100% right .... :P)
thx!!
Last edited by daniellumertz; 08-16-2020 at 04:50 PM.
Reason: forget the "not" in " is NOT 100% right"
local retval, str = reaper.GetItemStateChunk( item, "", false )
Msg(str)
local s, e = string.find(str, "SOURCE MIDI")
if s then --if it is and MIDI
Msg("MIDI")
else-- if it is an AUDIO ITEM
Msg("AUDIO")
end
Last edited by daniellumertz; 08-16-2020 at 07:07 PM.
local retval, str = reaper.GetItemStateChunk( item, "", false )
Msg(str)
local s, e = string.find(str, "SOURCE MIDI")
if s then --if it is and MIDI
Msg("MIDI")
else-- if it is an AUDIO ITEM
Msg("AUDIO")
end
(Though it doesn't necessarily mean false = audio take, could e.g. be a video take, if that's relevant for your script.)
Cool, So I need to destinguish between 3 scenarios A MIDI a AUDIO and a "EMPTY ITEM" (aka Note Item)
then I used the API Mespotine mentioned, but could Use take is MIDI also
Code:
take = reaper.GetMediaItemTake(item, 0)
if take then
source = reaper.GetMediaItemTake_Source(take)
typebuf = reaper.GetMediaSourceType( source, "")
Msg(typebuf)
if typebuf == "MIDI" then
--MIDI
else
--AUDIO
end
else
Msg("Note")
end
Oh, then it is stored in descending order. Root is on the right side
Hi, actually if you use this decimal to binary converter that I mounted it give it right.
Idk why using some online converters online the result is not the same, I followed up the instructions on the video that I posted, it shows how they transform from binary to decimals.
scale = 2741
scale_in_binary = {}
i = 0
while scale ~= 0 do
rest = scale % 2
scale = scale / 2
scale = math.floor(scale)
i = i + 1 --count of how many times it divided
scale_in_binary[i] = (rest) --store the rest in scale_in_binary
end
scale_in_string = table.concat(scale_in_binary)
Cool, So I need to destinguish between 3 scenarios A MIDI a AUDIO and a "EMPTY ITEM" (aka Note Item)
Just for completeness, Reaper also has these take types (hope I didn't miss any):
- click source
- timecode generator
- sub project (proxy)
- video processor
Hi, actually if you use this decimal to binary converter that I mounted it give it right.
Idk why using some online converters online the result is not the same, I followed up the instructions on the video that I posted, it shows how they transform from binary to decimals.
scale = 2741
scale_in_binary = {}
i = 0
while scale ~= 0 do
rest = scale % 2
scale = scale / 2
scale = math.floor(scale)
i = i + 1 --count of how many times it divided
scale_in_binary[i] = (rest) --store the rest in scale_in_binary
end
scale_in_string = table.concat(scale_in_binary)
So, the Reaper scales are saved in little endian
2048 + 1024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 111111111111
We thought it was big endian, that's why we got different scale than what it was
Assuming above is correct, then isn't the ReaScript doc for MIDI_GetScale wrong or I just don't understand it, as it says you have to deal with hex ('0x...') values?
Quote:
Get the active scale in the media source, if any. root 0=C, 1=C#, etc. scale &0x1=root, &0x2=minor 2nd, &0x4=major 2nd, &0x8=minor 3rd, &0xF=fourth, etc.
Assuming above is correct, then isn't the ReaScript doc for MIDI_GetScale wrong or I just don't understand it, as it says you have to deal with hex ('0x...') values?
0xF = 15 in decimal, what does it mean?
I didnt really understand what they ment there...
EDIT: I think they are refering to how much you add, root 1, minor second +2, etcc... but the fourth should be 32, also they missed the major third that is 16
In the RAW MIDI DATA they give the scale number in hex so need to convert to decimal to convert to binary to get the scale pattern
here I'm getting everything all right [not using the raw midi data]:
if you wanna test it
Code:
function number_to_note_sharp(root)
notes_table = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"}
root_class = notes_table[root+1]
return root_class
end
reaper.ShowConsoleMsg("")
local item = reaper.GetSelectedMediaItem(0,0)
take = reaper.GetMediaItemTake( item, 0 )
retval, root, scale, name = reaper.MIDI_GetScale( take, 0, 0, "" )
root_class = number_to_note_sharp(root)
reaper.ShowConsoleMsg("Root: "..tostring(root_class).."\n")
reaper.ShowConsoleMsg("Scale Number: "..tostring(scale).."\n")
reaper.ShowConsoleMsg("Scale Name: "..tostring(name).."\n")
scale_in_binary = {}
i = 0
while scale ~= 0 do
rest = scale % 2
scale = scale / 2
scale = math.floor(scale)
i = i + 1 --count of how many times it divided
scale_in_binary[i] = (rest) --store the rest in scale_in_binary
end
scale_in_string = table.concat(scale_in_binary)
reaper.ShowConsoleMsg("Scale Pattern: "..tostring(scale_in_string).."\n")
I think the MIDI_GetScale applies only to the "Key Snap"
Needs to use the MIDI_GetAllEvts to pick the changes in the item, but reaper seems to me full of bugs in this area it is even akward to try to change the key signature in the middle of an item... it becomes real difficult to try to make something using diatonic theory, tonal, modal...
I have some ideas for MIDI scripts but only the ones that don't have diatonic theory behind it can be done without an big workaround, I think.... or maybe there is some solutionss....
thx amagalma for the info didn't know about that !
Last edited by daniellumertz; 08-17-2020 at 08:40 PM.
but the fourth should be 32, also they missed the major third that is 16
Thanks.
That's what I assumed too, so shouldn't we report it?
On the other things I can't comment as I haven't done anything scripting-wise in that direction yet (actually I haven't really used Reaper's score editor so far).
Thanks.
That's what I assumed too, so shouldn't we report it?
On the other things I can't comment as I haven't done anything scripting-wise in that direction yet (actually I haven't really used Reaper's score editor so far).
should create a post in th bug session or send an email ?
item = reaper.GetSelectedMediaItem(0,0)
take = reaper.GetActiveTake(item)
ok, root, scale, name = reaper.MIDI_GetScale( take, 0, 0, 0 )
local t = {}
-- From scale number to binary
if ok then
for i = 0, 11 do
t[12-i] = scale & 2^i ~= 0 and 1 or 0
end
scale = table.concat(t)
end
-- From binary to scale number
if scale:len() == 12 then
scale_number = 0
i = 11
for digit in scale:gmatch("[01]") do
scale_number = scale_number + tonumber(digit)*2^i
i = i - 1
end
end
if i ~= -1 then scale_number = "error" end
Everything seems fine
Ah, now I read what is the problem.. Yes, the documentation seems to be wrong:
0x10 (16) major third
0x20 (32) perfect fourth
0x40 (64) augmented fourth etc
And it is not compulsory to use hex numbers...
Could someone of you write it in a way, that it's easy to understand where to put this how?
Would like to add this to my docs but I have absolutely no clue, what you are talking about so I couldn't explain it myself, sadly :/
Could someone of you write it in a way, that it's easy to understand where to put this how?
Would like to add this to my docs but I have absolutely no clue, what you are talking about so I couldn't explain it myself, sadly :/
It's about the doc for MIDI_GetScale which currently says:
Quote:
Get the active scale in the media source, if any. root 0=C, 1=C#, etc. scale &0x1=root, &0x2=minor 2nd, &0x4=major 2nd, &0x8=minor 3rd, &0xF=fourth, etc.
which we think is incorrect (unless Justin/schwa states otherwise) and should rather be something like (see posts above):
Quote:
Get the active scale in the media source, if any. root 0=C, 1=C#, etc. scale &0x1=root, &0x2=minor 2nd, &0x4=major 2nd, &0x8=minor 3rd, &0x10=major third, 0x20 perfect fourth, 0x40 augmented fourth, etc.
also would be cool to write a note saying the number gives the scale pattern (like 101011010101 major 2741 ) I think. A little more in hand for next people reading it