Old 07-24-2020, 10:41 AM   #1
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default The "how do I?" ReaScript thread

A thread for quick ReaScript questions (not worth opening a dedicated thread for).
nofish is offline   Reply With Quote
Old 07-24-2020, 10:55 AM   #2
LarrySeyer
Human being with feelings
 
LarrySeyer's Avatar
 
Join Date: Sep 2006
Location: Bastrop, Tx
Posts: 169
Default

Quote:
Originally Posted by nofish View Post
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.
LarrySeyer is offline   Reply With Quote
Old 07-24-2020, 02:00 PM   #3
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Quote:
Originally Posted by LarrySeyer View Post
How can I 'force' Reaper to ReLoad the keystrokes in the 'reaper-kb.ini' file without having to close and re-open Reaper?
Seems not possible currently:
https://forum.cockos.com/showthread.php?t=235141

There's also a FR:
https://forum.cockos.com/showthread.php?t=211295
nofish is offline   Reply With Quote
Old 07-24-2020, 04:08 PM   #4
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Couldn't you use the Action list > Key map > Export all, for all the different sets you want, then use the import to select which one to use?
Edgemeal is offline   Reply With Quote
Old 07-24-2020, 08:23 PM   #5
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,622
Default

Problem is, you need to go into the dialog to do that, though switching between different keymaps by shortcut would be nicer.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is online now   Reply With Quote
Old 07-25-2020, 09:05 PM   #6
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 565
Default

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.

Is it possible to do it?
dsyrock is offline   Reply With Quote
Old 07-25-2020, 09:59 PM   #7
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,622
Default

Use reaper.OpenMediaExplorer and give it a path instead of a file.
Set play to false.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is online now   Reply With Quote
Old 07-25-2020, 11:27 PM   #8
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 565
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
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.

Last edited by dsyrock; 07-27-2020 at 01:38 AM.
dsyrock is offline   Reply With Quote
Old 08-05-2020, 10:35 PM   #9
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

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.
daniellumertz is offline   Reply With Quote
Old 08-06-2020, 03:32 AM   #10
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by daniellumertz View Post
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

Nice, lydian it is
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 08-06-2020, 03:27 PM   #11
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Quote:
Originally Posted by amagalma View Post
Nice, lydian it is
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

Can someone else test it?
here a part of code
Code:
 function Msg(param)
   reaper.ShowConsoleMsg(tostring(param).."\n")
 end
 
reaper.ShowConsoleMsg("")

item = reaper.GetMediaItem( 0, 0 )
take = reaper.GetMediaItemTake( item, 0 )
retval, root, scale, name = reaper.MIDI_GetScale( take,0, 0,"" )
retval, selected, muted, startppqpos, endppqpos, chan, pitch, vel = reaper.MIDI_GetNote( take, 0 )
pitch_class = pitch % 12  
pitch_from_root = pitch_class - root 
--retval, buf = reaper.MIDI_GetAllEvts( take, buf )
Msg(scale)
why would they chose that ? hahaha


EDIT :

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.
daniellumertz is offline   Reply With Quote
Old 08-06-2020, 04:41 PM   #12
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,622
Default

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
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is online now   Reply With Quote
Old 08-06-2020, 05:44 PM   #13
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
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.

Reaper seems to be using an numbering for scales described in this site
https://ianring.com/musictheory/scales/

But I think there is something wrong in reaper and in the site.

The theory is very simple you have an binary number with 12 digits 1 represent a note in scale and 0 not in scale

Major scale (Tone tone semitone tone tone tone semitone) then would be 101011010101

this in decimals would be 2773 in wikipedia they agree with that https://en.wikipedia.org/wiki/Scale_(music)

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.
daniellumertz is offline   Reply With Quote
Old 08-06-2020, 07:31 PM   #14
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

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)
daniellumertz is offline   Reply With Quote
Old 08-10-2020, 08:28 AM   #15
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 565
Default

Is it possible to send a file or a folder to the clipboard in Lua? Then I can press Ctrl+V and paste to wherever I want.

Last edited by dsyrock; 08-10-2020 at 08:41 AM.
dsyrock is offline   Reply With Quote
Old 08-10-2020, 08:44 AM   #16
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,622
Default

Not yet. Maybe a feature request for sws.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is online now   Reply With Quote
Old 08-16-2020, 04:49 PM   #17
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Is there a way to get some config user is using?

I want to know the

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"
daniellumertz is offline   Reply With Quote
Old 08-16-2020, 06:58 PM   #18
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Can I add one more question?

how to know if an Media Item is MIDI or AUDIO?

Currently Iam using chunks

Code:
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.
daniellumertz is offline   Reply With Quote
Old 08-16-2020, 07:55 PM   #19
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,622
Default

Quote:
Originally Posted by daniellumertz View Post
Can I add one more question?

how to know if an Media Item is MIDI or AUDIO?

Currently Iam using chunks

Code:
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
Have a look at this:
https://mespotin.uber.space/Ultrasch...ediaSourceType

For user config settings, have a look at config vars:
https://mespotin.uber.space/Ultrasch...Variables.html
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is online now   Reply With Quote
Old 08-16-2020, 08:19 PM   #20
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

thanks as always Mespotine
daniellumertz is offline   Reply With Quote
Old 08-17-2020, 06:01 AM   #21
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

There's also TakeIsMIDI.

(Though it doesn't necessarily mean false = audio take, could e.g. be a video take, if that's relevant for your script.)
nofish is offline   Reply With Quote
Old 08-17-2020, 08:06 AM   #22
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Quote:
Originally Posted by nofish View Post
There's also TakeIsMIDI.

(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
thx
daniellumertz is offline   Reply With Quote
Old 08-17-2020, 09:06 AM   #23
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by daniellumertz View Post
Thanks for that message I noticed that something is wrong because 2741 I get from major not from Lydian.
Oh, then it is stored in descending order. Root is on the right side
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 08-17-2020, 11:29 AM   #24
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Quote:
Originally Posted by amagalma View Post
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.

111111111111
=
1+2+4+8+16+32+64+128+256+512+1024+2048 = 4095 ( Chromatic scale )

major scale in the video:


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)
daniellumertz is offline   Reply With Quote
Old 08-17-2020, 11:34 AM   #25
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Quote:
Originally Posted by daniellumertz View Post
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

Last edited by nofish; 08-17-2020 at 12:04 PM.
nofish is offline   Reply With Quote
Old 08-17-2020, 11:37 AM   #26
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,622
Default

Quote:
Originally Posted by daniellumertz View Post
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.

111111111111
=
1+2+4+8+16+32+64+128+256+512+1024+2048 = 4095 ( Chromatic scale )

major scale in the video:


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)
Where in Reaper do you set/get the scale?
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is online now   Reply With Quote
Old 08-17-2020, 11:44 AM   #27
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
Where in Reaper do you set/get the scale?
I have been setting here

I have not used much the notation editor but think It sets it also.

reaper.MIDI_GetScale
gets the scale from a midi item, wondering now what happen if there is a scale change in the middle of the item ...
daniellumertz is offline   Reply With Quote
Old 08-17-2020, 12:03 PM   #28
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Quote:
Originally Posted by daniellumertz View Post

111111111111
=
1+2+4+8+16+32+64+128+256+512+1024+2048 = 4095 ( Chromatic scale )
Binary can be little or big endian.

So, the Reaper scales are saved in big endian
2048 + 1024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 111111111111

We were writing them in little endian, that's why we got different scale than what it was
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 08-21-2020 at 04:03 AM.
amagalma is offline   Reply With Quote
Old 08-17-2020, 04:19 PM   #29
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Quote:
Originally Posted by amagalma View Post
Binary can be little or big endian.

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.
0xF = 15 in decimal, what does it mean?

Last edited by nofish; 08-17-2020 at 04:31 PM.
nofish is offline   Reply With Quote
Old 08-17-2020, 08:28 PM   #30
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Quote:
Originally Posted by nofish View Post
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...

bug example if you wanna get it a bump https://forum.cockos.com/showthread.php?t=240906

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.
daniellumertz is offline   Reply With Quote
Old 08-18-2020, 05:19 AM   #31
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Quote:
Originally Posted by daniellumertz View Post
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).
nofish is offline   Reply With Quote
Old 08-18-2020, 04:16 PM   #32
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Quote:
Originally Posted by nofish View Post
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 ?
daniellumertz is offline   Reply With Quote
Old 08-18-2020, 04:25 PM   #33
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

In the bug forum is fine I think.
Maybe something like 'API: doc for MIDI_GetScale probably wrong'?
nofish is offline   Reply With Quote
Old 08-18-2020, 04:35 PM   #34
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

https://forum.cockos.com/showthread....32#post2334232

created,
daniellumertz is offline   Reply With Quote
Old 08-19-2020, 01:39 AM   #35
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Code:
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...
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 08-19-2020 at 02:09 AM.
amagalma is offline   Reply With Quote
Old 08-19-2020, 05:38 AM   #36
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,622
Default

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 :/
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is online now   Reply With Quote
Old 08-19-2020, 05:55 AM   #37
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Quote:
Originally Posted by daniellumertz View Post
Thanks!
nofish is offline   Reply With Quote
Old 08-19-2020, 06:09 AM   #38
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
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.

It is not compulsory to use hex numbers.
bold = changes from original
nofish is offline   Reply With Quote
Old 08-19-2020, 06:16 AM   #39
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,622
Default

Thank you, will add that. And if the devs say otherwise, I will change again.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is online now   Reply With Quote
Old 08-19-2020, 06:17 AM   #40
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

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
daniellumertz is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:23 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.