Skip to content

Commit

Permalink
Update OneSmallStep v0.9 > v0.9.1 (#1320)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTalagan authored Feb 16, 2024
1 parent 9006160 commit 22bad17
Show file tree
Hide file tree
Showing 16 changed files with 907 additions and 304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ local mode = select(2, reaper.get_action_context()):match("%- ([^%s]*)%.lua$")

local engine_lib = require "talagan_OneSmallStep/talagan_OneSmallStep Engine lib";


if mode == 'OSS' then
engine_lib.setNoteLenMode(engine_lib.NoteLenMode.OSS);
engine_lib.setNoteLenParamSource(engine_lib.NoteLenParamSource.OSS);
elseif mode == 'ItemConf' then
engine_lib.setNoteLenMode(engine_lib.NoteLenMode.ItemConf);
engine_lib.setNoteLenParamSource(engine_lib.NoteLenParamSource.ItemConf);
elseif mode == 'ProjectGrid' then
engine_lib.setNoteLenMode(engine_lib.NoteLenMode.ProjectGrid);
engine_lib.setNoteLenParamSource(engine_lib.NoteLenParamSource.ProjectGrid);
end
109 changes: 109 additions & 0 deletions MIDI Editor/talagan_OneSmallStep Playback.lua
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);

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();
Loading

0 comments on commit 22bad17

Please sign in to comment.