-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update OneSmallStep v0.9 > v0.9.1 (#1320)
- Loading branch information
1 parent
9006160
commit 22bad17
Showing
16 changed files
with
907 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
-- @noindex | ||
-- @author Ben 'Talagan' Babut | ||
-- @license MIT | ||
-- @description This is part of One Small Step. Will replay the n last measures. | ||
|
||
package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path; | ||
local engine_lib = require "talagan_OneSmallStep/talagan_OneSmallStep Engine lib"; | ||
|
||
-- Give the possibility to this script to be duplicated and called | ||
-- With a param at the end of the lua file name (it overrides OSS config) | ||
local param = select(2, reaper.get_action_context()):match("%- ([^%s]*)%.lua$"); | ||
|
||
if reaper.set_action_options ~= nil then | ||
reaper.set_action_options(1); | ||
end | ||
|
||
-- Reaper must be in stalled state | ||
if not (reaper.GetPlayState() == 0) then | ||
return; | ||
end | ||
|
||
local rewindMeasureCount = ((param == nil) and engine_lib.getPlaybackMeasureCount() or tonumber(param)); | ||
|
||
local pos = reaper.GetCursorPosition(); | ||
local posqn = reaper.TimeMap2_timeToQN(0, pos); | ||
local posm = reaper.TimeMap_QNToMeasures(0, posqn); | ||
|
||
local timeStart = 0; | ||
|
||
if rewindMeasureCount == -1 then | ||
local mkid, mkpos = engine_lib.findPlaybackMarker(); | ||
if mkid == nil then | ||
rewindMeasureCount = 0 | ||
else | ||
timeStart = mkpos; | ||
end | ||
end | ||
|
||
if rewindMeasureCount >= 0 then | ||
-- Determine the right measure start | ||
local _, thisMeasureStart, thisMeasureEnd = reaper.TimeMap_GetMeasureInfo(0, posm - 1); | ||
|
||
if math.abs(thisMeasureStart - posqn) < 0.01 and rewindMeasureCount == 0 then | ||
-- If the cursor is on the start of one measure, move 1 one more measure backward | ||
rewindMeasureCount = 1; | ||
end | ||
|
||
local _, measureStart, measureEnd = reaper.TimeMap_GetMeasureInfo(0, posm - 1 - rewindMeasureCount); | ||
|
||
timeStart = reaper.TimeMap2_QNToTime(0, measureStart); | ||
end | ||
|
||
|
||
|
||
-- In OSS manual, I encourage users to a tick the option that | ||
-- creates an undo point whenever the Edit cursor is moved | ||
-- This ensures that OSS undo works well (notes are cancelled and the edit cursor moves back to its previous position) | ||
-- Hovever, for the playback action, it may create unwanted undo points | ||
|
||
-- That's why, at the end we check if undo points were created during playback and we cancel them. | ||
|
||
local SPBA = "OneSmallStep - Start Playback"; | ||
local EPBA = "OneSmallStep - End Playback"; | ||
|
||
function startPlayback() | ||
-- Move the cursor back and hit play | ||
reaper.Undo_BeginBlock(); | ||
reaper.SetEditCurPos(timeStart, true, true); | ||
reaper.Undo_EndBlock(SPBA,0); | ||
reaper.OnPlayButton(); | ||
reaper.defer(waitEndOfPlayback); | ||
end | ||
|
||
function onPlaybackEnd() | ||
reaper.Undo_BeginBlock(); | ||
reaper.SetEditCurPos(pos, false, false); | ||
reaper.Undo_EndBlock(EPBA,0); | ||
|
||
-- We cannot prevent reaper from creating undo points | ||
local last_action = reaper.Undo_CanUndo2(0); | ||
while last_action == SPBA or last_action == EPBA do | ||
reaper.Undo_DoUndo2(0); | ||
last_action = reaper.Undo_CanUndo2(0); | ||
end | ||
|
||
end | ||
|
||
function waitEndOfPlayback() | ||
|
||
local ps = reaper.GetPlayState(); | ||
local curtime = reaper.GetPlayPosition(); | ||
local antiglitch = 0.05; | ||
|
||
if curtime < pos - antiglitch and ps == 1 then | ||
reaper.defer(waitEndOfPlayback); | ||
else | ||
return; | ||
end | ||
|
||
end | ||
|
||
function stopPlayback() | ||
reaper.OnStopButton(); | ||
onPlaybackEnd(); | ||
end | ||
|
||
reaper.defer(startPlayback); | ||
reaper.atexit(stopPlayback); | ||
|
9 changes: 9 additions & 0 deletions
9
MIDI Editor/talagan_OneSmallStep Set or remove playback marker.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- @noindex | ||
-- @author Ben 'Talagan' Babut | ||
-- @license MIT | ||
-- @description This is part of One Small Step. Will replay the n last measures. | ||
|
||
package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path; | ||
local engine_lib = require "talagan_OneSmallStep/talagan_OneSmallStep Engine lib"; | ||
|
||
engine_lib.setPlaybackMarkerAtCurrentPos(); |
Oops, something went wrong.