|
|
|
06-18-2019, 04:57 PM
|
#1
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
Move Cursor to Next Beat
There doesn't seem to be anything in the API's to go to measure/beat it all seems to be time.
I just need to move the cursor to the next beat
reaper.Main_OnCommand(41044, 0) -- Move edit cursor forward one beat
is moving 2 beats forward.
If I use as a command Script: spk77_Move edit cursor forward by 1 frame (or 1 beat).eel
it works but I don't want to call on it externally from the script so I would like to add it as a
function in the Lua script:
eel code
Code:
function move_cursor_right() local(snap, grid_vis, state, beat_in_meas, meas, closest_beat_in_secs)
(
GetToggleCommandState(40370) ? state = 1 : state = 0;
!state ? ( // ruler time unit is not "H:M:S:F"
beat_in_meas = TimeMap2_timeToBeats(0, GetCursorPosition(), meas, 0, 0, 0);
closest_beat_in_secs = TimeMap2_beatsToTime(0, floor(beat_in_meas + 0.5), meas);
closest_beat_in_secs > GetCursorPosition() ? (
SetEditCurPos(TimeMap2_beatsToTime(0, floor(beat_in_meas + 0.5), meas), 1, 0);
) : (
SetEditCurPos(TimeMap2_beatsToTime(0, floor(beat_in_meas + 0.5) + 1, meas), 1, 0);
);
) : ( // ruler time unit is "H:M:S:F"
ApplyNudge(0, 2, 6, 18, 0.501, 0, 0); // nudge edit cursor right by 0.501 frames (snap to unit)
);
Undo_OnStateChange("Move edit cursor right by 1 frame (or 1 beat)");
);
but I can't get the Lua translation
Code:
--GetToggleCommandState(40370) ? state = 1 : state = 0;
state = reaper.GetToggleCommandState( 40370 )
if state == 0 then -- ruler time unit is not "H:M:S:F"
beat_in_meas = reaper.TimeMap2_timeToBeats(0, reaper.GetCursorPosition(), meas, 0, 0, 0)
closest_beat_in_secs = reaper.TimeMap2_beatsToTime(0, math.floor(beat_in_meas + 0.5), meas)
if closest_beat_in_secs > reaper.GetCursorPosition() then
reaper.SetEditCurPos(reaper.TimeMap2_beatsToTime(0, math.floor(beat_in_meas + 0.5), meas), 1, 0)
reaper.SetEditCurPos(reaper.TimeMap2_beatsToTime(0, math.floor(beat_in_meas + 0.5) + 1, meas), 1, 0)
end
end
if state == 1 then -- ruler time unit is "H:M:S:F"
reaper.ApplyNudge(0, 2, 6, 18, 0.501, 0, 0); -- nudge edit cursor right by 0.501 frames (snap to unit)
end
|
|
|
06-18-2019, 05:34 PM
|
#2
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
it's simple when you find out how !
Code:
cur_pos = reaper.GetCursorPosition()
retval, measures, cml, fullbeats, cdenom = reaper.TimeMap2_timeToBeats(0, cur_pos)
current_measure = reaper.TimeMap2_beatsToTime(0, fullbeats +1)
reaper.SetEditCurPos2( 0, current_measure, 0, 0 )
|
|
|
06-21-2019, 09:34 PM
|
#3
|
Human being with feelings
Join Date: Oct 2008
Location: Right Hear
Posts: 15,618
|
now Bob... there is a 'signature quote'
Quote:
it's simple when you find out how !
|
so how about the reverse lua? previous beat
Last edited by hopi; 06-21-2019 at 09:45 PM.
|
|
|
06-21-2019, 10:09 PM
|
#4
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
Move Cursor to Prevoius Beat
Code:
cur_pos = reaper.GetCursorPosition()
retval, measures, cml, fullbeats, cdenom = reaper.TimeMap2_timeToBeats(0, cur_pos)
current_measure = reaper.TimeMap2_beatsToTime(0, fullbeats -1)
reaper.SetEditCurPos2( 0, current_measure, 0, 0 )
|
|
|
06-22-2019, 06:17 AM
|
#5
|
Human being with feelings
Join Date: Oct 2008
Location: Right Hear
Posts: 15,618
|
great! thanks Bob
|
|
|
06-22-2019, 06:49 AM
|
#6
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,109
|
Note that TimeMap2_timeToBeats() / TimeMap2_beatsToTime() don't take into account if a swing grid is set:
https://forum.cockos.com/showthread.php?t=220305
Justin posted some code for it in that thread.
Last edited by nofish; 06-22-2019 at 07:13 AM.
|
|
|
06-22-2019, 07:26 PM
|
#7
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
Quote:
Originally Posted by nofish
Note that TimeMap2_timeToBeats() / TimeMap2_beatsToTime() don't take into account if a swing grid is set...
|
Thanks I'll look into that more. I just created another script below to insert a stretch marker @ every beat depending what the grid is set to then it will snap the first stretch marker to the first beat and so on to fit the constant tempo item to the project's tempo map. If you can try it with your swing grid as it may not work if the stretch markers are not offset for the swing in the source item ??
Quote:
Originally Posted by MusoBob
|
|
|
|
06-23-2019, 08:29 AM
|
#8
|
Human being with feelings
Join Date: Oct 2008
Location: Right Hear
Posts: 15,618
|
Bob... it would be nice if you had your own repository on Reapack... so we can find just your scripts in a folder, like say, "MusoBob"... within the Scripts folder
OH... and it would be way nice if these scripts were OK in the MIDI Ed. actions list... must be a small thing to add???
Last edited by hopi; 06-24-2019 at 12:01 PM.
|
|
|
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 07:26 PM.
|