Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 03-30-2022, 12:33 AM   #1
Kaxaze music
Human being with feelings
 
Kaxaze music's Avatar
 
Join Date: Sep 2020
Location: India
Posts: 283
Default i want a script that can tell that the project grid is "triplet" or not

Hello, how are you?

So, i am making a script that opens selected midi item in the Midi editor. so, i want the script to set midi editor grid to triplet if the project grid is set to triplet.
Kaxaze music is offline   Reply With Quote
Old 03-30-2022, 12:51 AM   #2
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

taken from some random place so probably not exact right code, replace Midi editor value with arrange one:
Code:
grid_division= MIDI_GetGrid( take )
grid_division = grid_division/4
local denom = 1/grid_division
if denom >=2 then 
  is_triplet = (1/grid_division) % 3 == 0 
 else 
  is_triplet = math.abs(grid_division - 0.6666) < 0.001
end
mpl is offline   Reply With Quote
Old 03-30-2022, 12:59 AM   #3
Kaxaze music
Human being with feelings
 
Kaxaze music's Avatar
 
Join Date: Sep 2020
Location: India
Posts: 283
Default

seems like it will tell me if the midi editor grid is set to triplet or not
Kaxaze music is offline   Reply With Quote
Old 03-30-2022, 01:12 AM   #4
Kaxaze music
Human being with feelings
 
Kaxaze music's Avatar
 
Join Date: Sep 2020
Location: India
Posts: 283
Default

I am going this route

Code:
--to set the grid to triplet if the project is set to triplet
local retval1, gridSize = reaper.GetSetProjectGrid(0, false)
local biggestTripletGrid = 0.16666666666667
  
if gridSize == biggestTripletGrid or gridSize == biggestTripletGrid / 2 or gridSize == biggestTripletGrid / 4 or gridSize == biggestTripletGrid / 8 then 
    reaper.SetMIDIEditorGrid(gridSize)
    reaper.ShowConsoleMsg("true")
else
    reaper.ShowConsoleMsg("false")
end
but it always prints "false" to the console that means it doesn't executes the "reaper.SetMIDIEditorGrid(gridSize)" function
Kaxaze music is offline   Reply With Quote
Old 03-30-2022, 02:05 AM   #5
BenjyO
Human being with feelings
 
Join Date: Nov 2011
Posts: 308
Default

Quote:
Originally Posted by Kaxaze music View Post
I am going this route

Code:
--to set the grid to triplet if the project is set to triplet
local retval1, gridSize = reaper.GetSetProjectGrid(0, false)
local biggestTripletGrid = 0.16666666666667
  
if gridSize == biggestTripletGrid or gridSize == biggestTripletGrid / 2 or gridSize == biggestTripletGrid / 4 or gridSize == biggestTripletGrid / 8 then 
    reaper.SetMIDIEditorGrid(gridSize)
    reaper.ShowConsoleMsg("true")
else
    reaper.ShowConsoleMsg("false")
end
but it always prints "false" to the console that means it doesn't executes the "reaper.SetMIDIEditorGrid(gridSize)" function
There were 2 problems in your example:
1. The value you assigned to the "biggestTripletGrid" variable is a rounded number while Reaper holds a number with a higher number of decimals stored within the "gridSize" variable. That's why your comparison of "gridSize" and "biggestTripletGrid" always fails.
2. The "SetMIDIEditorGrid" function has 2 parameters and the first one is the project (set 0 for active project) and the 2nd one is grid size.

Corrected below (sets MIDI editor grid to 1/4 triplet):
Code:
--to set the grid to triplet if the project is set to triplet
local retval1, gridSize = reaper.GetSetProjectGrid(0, false)
local biggestTripletGrid = 1/3
  
if gridSize == biggestTripletGrid or gridSize == biggestTripletGrid / 2 or gridSize == biggestTripletGrid / 4 or gridSize == biggestTripletGrid / 8 then 
    reaper.SetMIDIEditorGrid(0, gridSize)
    reaper.ShowConsoleMsg("true")
else
    reaper.ShowConsoleMsg("false")
end
__________________
Check out some of my music
BenjyO is offline   Reply With Quote
Old 03-30-2022, 02:11 AM   #6
BenjyO
Human being with feelings
 
Join Date: Nov 2011
Posts: 308
Default

Oh and btw, this action/option could maybe help you - not necessarily what you wanted but maybe it satisfies your needs:
Grid: Use the same grid division in arrange view and MIDI editor
__________________
Check out some of my music
BenjyO is offline   Reply With Quote
Old 03-30-2022, 05:56 AM   #7
Kaxaze music
Human being with feelings
 
Kaxaze music's Avatar
 
Join Date: Sep 2020
Location: India
Posts: 283
Default

Quote:
Originally Posted by BenjyO View Post
There were 2 problems in your example:
1. The value you assigned to the "biggestTripletGrid" variable is a rounded number while Reaper holds a number with a higher number of decimals stored within the "gridSize" variable. That's why your comparison of "gridSize" and "biggestTripletGrid" always fails.
2. The "SetMIDIEditorGrid" function has 2 parameters and the first one is the project (set 0 for active project) and the 2nd one is grid size.

Corrected below (sets MIDI editor grid to 1/4 triplet):
Code:
--to set the grid to triplet if the project is set to triplet
local retval1, gridSize = reaper.GetSetProjectGrid(0, false)
local biggestTripletGrid = 1/3
  
if gridSize == biggestTripletGrid or gridSize == biggestTripletGrid / 2 or gridSize == biggestTripletGrid / 4 or gridSize == biggestTripletGrid / 8 then 
    reaper.SetMIDIEditorGrid(0, gridSize)
    reaper.ShowConsoleMsg("true")
else
    reaper.ShowConsoleMsg("false")
end
Ohh that was helpfull thank you ��
Kaxaze music is offline   Reply With Quote
Old 03-30-2022, 05:57 AM   #8
Kaxaze music
Human being with feelings
 
Kaxaze music's Avatar
 
Join Date: Sep 2020
Location: India
Posts: 283
Default

Quote:
Originally Posted by BenjyO View Post
Oh and btw, this action/option could maybe help you - not necessarily what you wanted but maybe it satisfies your needs:
Grid: Use the same grid division in arrange view and MIDI editor
i knew about that option
Kaxaze music 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:59 PM.


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