Skip to content

Commit

Permalink
Update OneSmallStep v0.8 > v0.9 (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTalagan authored Feb 13, 2024
1 parent fde9a79 commit d1f1b8a
Show file tree
Hide file tree
Showing 7 changed files with 514 additions and 328 deletions.
634 changes: 346 additions & 288 deletions MIDI Editor/talagan_OneSmallStep.lua

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions MIDI Editor/talagan_OneSmallStep/images/input_mode_action.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- @noindex
-- @author Ben 'Talagan' Babut
-- @license MIT
-- @description This is part of One Small Step

return "\z
\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49\x48\x44\x52\x00\x00\x00\x1E\x00\x00\x00\x1E\x08\x06\x00\x00\x00\x3B\x30\xAE\xA2\x00\x00\x00\x09\x70\x48\x59\z
\x73\x00\x00\x0B\x13\x00\x00\x0B\x13\x01\x00\x9A\x9C\x18\x00\x00\x00\xF1\x49\x44\x41\x54\x48\x89\xED\x96\xDD\x6D\xC2\x30\x14\x85\xBF\x54\xBC\x9E\x87\xAE\x10\x46\z
\x60\x05\x3A\x02\x2B\xB0\x42\x33\x4B\x47\xE8\x0C\xCC\xC2\x0A\x3C\x9C\x01\xCC\x43\x4D\x95\xA6\xC4\xB1\x43\x22\x10\xE4\x48\x56\x24\xFF\xE4\xCB\xBD\xB9\xC7\x76\x15\z
\x42\xE0\x1E\x7A\xBB\x0B\x75\x01\x2F\xE0\x39\xB5\x4A\x0D\xDA\xBE\xC9\x6B\x92\xAA\x51\xE0\x96\x7A\x5F\xD0\xA3\xC1\x0F\xCE\x01\x57\x92\x92\x13\x6C\xFF\x5B\x33\x04\z
\x2F\xFA\xC7\xB6\x6B\xDB\xC1\xF6\xAE\xDD\x2F\xE9\x4F\xCB\x51\x69\x71\xED\x80\x23\xB0\x4F\x4D\xCA\x81\x97\x82\x3F\x81\x06\xD8\xD8\xAE\x2F\x9D\x57\x52\x3D\x1D\x38\z
\xA6\xF7\x1D\xF8\x8E\xCF\xDF\x74\x4B\x2A\x86\x97\x44\xBC\x07\x9A\x68\x91\x0F\x7E\xA2\x1F\xAD\x2C\x70\x4C\xEB\x16\xF8\x02\x90\x74\x00\x4E\xDD\x22\x2B\x51\x96\x8F\z
\x25\x1D\xE9\x78\x59\xD2\x7A\x2C\x14\x1E\x75\xCB\xEC\x53\xB7\x90\x72\xBD\x7B\x13\xF8\x02\x6D\xC3\x66\xB5\xD3\xD4\xAA\x52\x97\xBD\xD6\xE9\x34\xB8\x5F\x5F\x5B\x37\z
\xC5\xE9\x14\xC6\xA4\x33\xA5\x64\xC4\x73\xEA\xF5\xAE\x3E\x0B\xF8\xF9\xC1\x67\xBD\x40\x4D\x7E\x16\x4F\xA5\x13\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82"
;
12 changes: 12 additions & 0 deletions MIDI Editor/talagan_OneSmallStep/images/input_mode_keyboard.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- @noindex
-- @author Ben 'Talagan' Babut
-- @license MIT
-- @description This is part of One Small Step

return "\z
\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49\x48\x44\x52\x00\x00\x00\x1E\x00\x00\x00\x1E\x08\x06\x00\x00\x00\x3B\x30\xAE\xA2\x00\x00\x00\x09\x70\x48\x59\z
\x73\x00\x00\x0B\x13\x00\x00\x0B\x13\x01\x00\x9A\x9C\x18\x00\x00\x00\x72\x49\x44\x41\x54\x48\x89\xED\xD6\x31\x0A\xC0\x20\x0C\x05\xD0\xA6\x74\xFD\xF7\x3F\x68\x0E\z
\x90\x2E\x1D\x4A\x3B\x7C\x83\x89\x19\xCC\x07\x11\x25\xF0\x10\x45\x22\x66\x76\x54\xE4\x2C\x51\x1B\x5E\x99\x8B\x15\xA8\xAA\xFB\xF5\x01\x10\x56\x33\x7A\x62\x79\xC6\z
\x77\x8F\xD5\x4C\xC3\xE1\x19\x86\x01\x84\xD4\xB8\xE1\xE8\x34\xDC\x70\xC3\x65\xB0\x90\x39\x0D\x0E\x8B\x0B\x7E\x7F\x89\x00\x7E\xEB\x34\x38\x32\x0D\x2F\x8B\xB0\xBE\z
\x3A\xAB\xF5\xA1\x70\x56\xF6\xBB\xE3\xFD\xE0\x1B\x8E\x65\x12\x26\xB0\xF6\xFA\x14\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82"
;
13 changes: 13 additions & 0 deletions MIDI Editor/talagan_OneSmallStep/images/input_mode_pedal.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- @noindex
-- @author Ben 'Talagan' Babut
-- @license MIT
-- @description This is part of One Small Step

return "\z
\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49\x48\x44\x52\x00\x00\x00\x1E\x00\x00\x00\x1E\x08\x06\x00\x00\x00\x3B\x30\xAE\xA2\x00\x00\x00\x09\x70\x48\x59\z
\x73\x00\x00\x0B\x13\x00\x00\x0B\x13\x01\x00\x9A\x9C\x18\x00\x00\x00\x8B\x49\x44\x41\x54\x48\x89\xED\x96\xDD\x0A\xC0\x20\x08\x85\x6D\xEC\xD6\xF7\x7F\x50\x1F\xC0\z
\xDD\x34\x08\x96\xF9\xB3\xB6\xC6\xF0\x40\x37\x91\x7C\x9E\x32\xB1\x30\x33\xAC\xD0\xB6\x84\x9A\xE0\x04\xFF\x12\xBC\xF7\x36\x89\x68\xEA\xE7\x46\xC4\x62\x02\x57\x5D\z
\x0E\x07\x24\x1A\x18\x81\xDB\x40\x6F\x12\x6A\x9C\x06\xF6\xCA\x9C\xA8\x06\xB6\x3A\x75\xDF\xCC\x1D\xC7\xED\xFB\xB9\xEB\x61\xF8\x9D\x10\x51\x02\x72\x85\x9D\xCB\x2D\z
\x8F\xE3\x68\xA1\x85\xC1\x53\x81\x16\x30\x13\x51\x2F\x81\x88\x5E\x6F\x20\x00\x42\xC2\xDF\xEA\xD5\x55\x8F\x0E\x63\x25\x87\xBD\x04\x27\x38\xC1\x51\x1D\xA7\xD7\x1B\z
\x4B\x21\x43\x68\xA5\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82"
;
15 changes: 15 additions & 0 deletions MIDI Editor/talagan_OneSmallStep/images/note_modified.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- @noindex
-- @author Ben 'Talagan' Babut
-- @license MIT
-- @description This is part of One Small Step

return "\z
\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49\x48\x44\x52\x00\x00\x00\x1E\x00\x00\x00\x1E\x08\x06\x00\x00\x00\x3B\x30\xAE\xA2\x00\x00\x00\x09\x70\x48\x59\z
\x73\x00\x00\x0B\x13\x00\x00\x0B\x13\x01\x00\x9A\x9C\x18\x00\x00\x00\xE8\x49\x44\x41\x54\x48\x89\xED\x96\x31\x0A\xC2\x30\x14\x86\xBF\x88\xE2\xF4\x86\x0E\x82\x73\z
\x5D\xDC\xF5\x08\x3D\x81\xA0\x27\x71\xF0\x0A\xBD\x82\x38\xBA\xA8\x57\x70\xF0\x00\x16\xBC\x80\xBD\x82\x43\xA6\x1A\xA1\x0E\xAD\x50\x34\x05\x2B\xD5\x0E\xE6\x87\x07\z
\x79\xC9\x4B\x3E\xDE\x7B\x24\x44\xA5\x69\x4A\x13\x6A\x35\x42\x75\x60\x07\x2E\x4A\x29\xF5\x62\xD7\xDB\xED\xF4\x75\x70\x89\xFA\x4D\x81\x3F\x96\x03\x3B\xB0\x03\x3B\z
\xF0\xC7\x6A\x57\xDD\x90\x18\x33\x01\x7A\x3F\x05\x27\xC6\x1C\x80\xA1\x6D\x4D\x6B\xED\x03\xE7\xDC\x9D\x01\x5B\x60\x21\x22\xA1\x2D\xFE\xED\x52\x27\xC6\xAC\x2C\x50\z
\xF3\x18\x88\x48\x0C\x2C\x80\x18\x08\x80\x3D\xE0\x95\x9D\x57\xA5\xC7\x63\xCB\xDC\xE6\xC9\x1F\x01\x3E\x10\xE6\xE3\xA8\x0E\x70\x11\x62\x80\x75\xB7\xD3\x99\x3F\xC5\z
\x04\xC0\x92\x2C\x53\x8F\x2C\x6B\xAB\x54\x5D\xDF\x5B\xAD\xF5\x08\x38\x02\x03\x60\x9A\x5B\x28\x22\x3B\x5B\x7C\x9D\xD7\x29\x00\xA2\xBC\xD7\x90\x95\xFC\x52\x16\x5C\z
\x5B\xC6\x55\xF5\x7F\x2F\xD7\xFF\x81\xEF\x0F\x62\x32\xD0\x63\x1C\xF7\xDF\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82"
;
153 changes: 113 additions & 40 deletions MIDI Editor/talagan_OneSmallStep/talagan_OneSmallStep Engine lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,54 @@ package.path = scriptDir .."?.lua;".. package.path
local helper_lib = require "talagan_OneSmallStep Helper lib";

-- Defines
local noteLenLookup = {
["1"] = {next="1", prec="1_2", qn=4 },
["1_2"] = {next="1", prec="1_4", qn=2 },
["1_4"] = {next="1_2", prec="1_8", qn=1 },
["1_8"] = {next="1_4", prec="1_16", qn=0.5 },
["1_16"] = {next="1_8", prec="1_32", qn=0.25 },
["1_32"] = {next="1_16", prec="1_64", qn=0.125 },
["1_64"] = {next="1_32", prec="1_64", qn=0.0625 }
local NoteLenDefs = {
{ id = "1", next = "1", prec = "1_2", qn = 4 },
{ id = "1_2", next = "1", prec = "1_4", qn = 2 },
{ id = "1_4", next = "1_2", prec = "1_8", qn = 1 },
{ id = "1_8", next = "1_4", prec = "1_16", qn = 0.5 },
{ id = "1_16", next = "1_8", prec = "1_32", qn = 0.25 },
{ id = "1_32", next = "1_16", prec = "1_64", qn = 0.125 },
{ id = "1_64", next = "1_32", prec = "1_64", qn = 0.0625 }
};
local AugmentedDiminishedDefs = {
{ id = '1/2', mod = 1 / 2.0 },
{ id = '1/3', mod = 1 / 3.0 },
{ id = '2/3', mod = 2 / 3.0 },
{ id = '1/4', mod = 1 / 4.0 },
{ id = '3/4', mod = 3 / 4.0 },
{ id = '1/5', mod = 1 / 5.0 },
{ id = '2/5', mod = 2 / 5.0 },
{ id = '3/5', mod = 3 / 5.0 },
{ id = '4/5', mod = 4 / 5.0 },
{ id = '1/6', mod = 1 / 6.0 },
{ id = '5/6', mod = 5 / 6.0 },
{ id = '1/7', mod = 1 / 7.0 },
{ id = '2/7', mod = 2 / 7.0 },
{ id = '3/7', mod = 3 / 7.0 },
{ id = '4/7', mod = 4 / 7.0 },
{ id = '5/7', mod = 5 / 7.0 },
{ id = '6/7', mod = 6 / 7.0 },
{ id = '1/8', mod = 1 / 8.0 },
{ id = '3/8', mod = 3 / 8.0 },
{ id = '5/8', mod = 5 / 8.0 },
{ id = '7/8', mod = 7 / 8.0 },
{ id = '1/9', mod = 1 / 9.0 },
{ id = '2/9', mod = 2 / 9.0 },
{ id = '4/9', mod = 4 / 9.0 },
{ id = '5/9', mod = 5 / 9.0 },
{ id = '7/9', mod = 7 / 9.0 },
{ id = '8/9', mod = 8 / 9.0 }
}

local NoteLenLookup = {};
for i,v in ipairs(NoteLenDefs) do
NoteLenLookup[v.id] = v;
end

local AugmentedDiminishedLookup = {};
for i,v in ipairs(AugmentedDiminishedDefs) do
AugmentedDiminishedLookup[v.id] = v;
end

local NoteLenMode = {
OSS=0,
Expand All @@ -38,21 +77,17 @@ local NoteLenModifier = {
Straight=0,
Dotted=1,
Triplet=2,
Tuplet=3
Tuplet=3,
Modified=4
}


local function DBG(m)
--reaper.ShowConsoleMsg(m .. "\n");
end

-----------

local function setMode(m)
local function setInputMode(m)
reaper.SetExtState("OneSmallStep", "Mode", tostring(m), true)
end
local function getMode()
return tonumber(reaper.GetExtState("OneSmallStep", "Mode")) or 0;
local function getInputMode()
return tonumber(reaper.GetExtState("OneSmallStep", "Mode")) or InputMode.Keyboard;
end

-----------
Expand All @@ -66,6 +101,24 @@ end

-----------

local function setNoteADSign(plus_or_minus)
reaper.SetExtState("OneSmallStep", "NoteLenADSign", plus_or_minus, true)
end
local function getNoteADSign()
return reaper.GetExtState("OneSmallStep", "NoteLenADSign") or "+";
end

-----------

local function setNoteADFactor(fraction_string)
reaper.SetExtState("OneSmallStep", "NoteADFactor", fraction_string, true)
end
local function getNoteADFactor()
return reaper.GetExtState("OneSmallStep", "NoteADFactor") or "1/2";
end

-----------

local function setTupletDivision(m)
reaper.SetExtState("OneSmallStep", "TupletDivision", tostring(m), true)
end
Expand Down Expand Up @@ -94,6 +147,9 @@ end
local function getNoteLenModifier()
return tonumber(reaper.GetExtState("OneSmallStep", "NoteLenModifier"));
end

-----------

local function getNoteLenModifierFactor()

local m = getNoteLenModifier();
Expand All @@ -104,6 +160,11 @@ local function getNoteLenModifierFactor()
return 1.5;
elseif m == NoteLenModifier.Triplet then
return 2/3.0;
elseif m == NoteLenModifier.Modified then
local sign = getNoteADSign();
local factor = AugmentedDiminishedLookup[getNoteADFactor()].mod;

return 1 + (sign == '+' and 1 or -1) * factor;
elseif m == NoteLenModifier.Tuplet then
local div = getTupletDivision();
return 2.0/div;
Expand All @@ -114,18 +175,18 @@ end

local function increaseNoteLen()
local l = getNoteLen();
setNoteLen(noteLenLookup[l].next);
setNoteLen(NoteLenLookup[l].next);
end

local function decreaseNoteLen()
local l = getNoteLen();
setNoteLen(noteLenLookup[l].prec);
setNoteLen(NoteLenLookup[l].prec);
end

local function getNoteLenQN()
local nl = getNoteLen();

return noteLenLookup[nl].qn;
return NoteLenLookup[nl].qn;
end


Expand Down Expand Up @@ -287,7 +348,7 @@ end
-- Table to keep track of key activities
-- With inertia, to avoid losing events for chords
-- When releasing keys (the release events may not be totally synchronized)
local trackKeyActivity = {};
local trackKeyActivity = {}; -- trackid -> { "chan,note" -> { :note, :chan, :velocity, :ts } }
local keyInertia = 0.2;

local function keepTrackOfKeysForTrack(track, pressed_keys)
Expand All @@ -301,10 +362,10 @@ local function keepTrackOfKeysForTrack(track, pressed_keys)
for _, v in pairs(pressed_keys) do
local k = tostring(math.floor(v.chan+0.5)) .. "," .. tostring(math.floor(v.note+0.5))
trackKeyActivity[trackid][k] = {
note=v.note,
chan=v.chan,
velocity=v.velocity,
ts=t
note = v.note,
chan = v.chan,
velocity = v.velocity,
ts = t
};
end
end
Expand All @@ -317,8 +378,6 @@ local function keyActivityForTrack(track)
return {}
end

ttta = track_activity;

local ret = {};
for _, v in pairs(track_activity) do
ret[#ret+1] = v;
Expand All @@ -339,6 +398,8 @@ local function clearOutdatedTrackActivity()
for guid, track_activity in pairs(trackKeyActivity) do
local torem = {};
for k, note_info in pairs(track_activity) do
-- The key is not held anymore, for more than the inertia time
-- Remove it
if t - note_info.ts > keyInertia then
torem[#torem+1] = k
end
Expand All @@ -356,7 +417,7 @@ end
-- Listen to events from instrumented tracks that have the JSFX companion effect installed (or install it if not present)
local function listenToEvents(called_from_action)

local mode = getMode();
local mode = getInputMode();

-- Input mode should be engaged
if mode == InputMode.None then
Expand Down Expand Up @@ -391,10 +452,10 @@ local function listenToEvents(called_from_action)
local oss_state = helper_lib.oneSmallStepState(track);

if mode == InputMode.Pedal then

if oss_state.pedalActivity > 0 or called_from_action then
-- Pedal event, commit new notes
reaper.Undo_BeginBlock();
-- Acknowledge the pedal
helper_lib.resetPedalActivity(track);
commit(take, oss_state.pitches);
reaper.Undo_EndBlock("One Small Step - Add notes on pedal event",-1);
Expand Down Expand Up @@ -426,11 +487,12 @@ local function listenToEvents(called_from_action)
end
end

-- Allow the use of the action, but only insert rests
if called_from_action then
-- Allow the use of the action or pedal, but only insert rests
if oss_state.pedalActivity > 0 or called_from_action then
reaper.Undo_BeginBlock();
helper_lib.resetPedalActivity(track);
commit(take, {}) ;
reaper.Undo_EndBlock("One Small Step - Add rest on action",-1);
reaper.Undo_EndBlock("One Small Step - Add rest",-1);
end
end

Expand All @@ -440,22 +502,24 @@ function reaperActionCommit()
listenToEvents(true);
end

function cleanupCompanionFXs()
reaper.Undo_BeginBlock()
helper_lib.cleanupAllTrackFXs();
reaper.Undo_EndBlock("One Small Step - Cleanup companion JSFXs",-1);
end

function atStart()
-- Do some cleanup at engine start
-- But this adds an undo entry point ...
-- So rely on the user instead to cleanup the JSFXs using the relevant action
-- If there's one day a way to prevent reaper from creating Undo points
-- Then we can uncomment this automatic cleanup
--reaper.Undo_BeginBlock()
--helper_lib.cleanupAllTrackFXs();
--reaper.Undo_EndBlock("One Small Step - Cleanup companion JSFXs",-1);
-- cleanupCompanionFXs();
end

function atExit()
-- See comment in atStart
--reaper.Undo_BeginBlock()
--helper_lib.cleanupAllTrackFXs();
--reaper.Undo_EndBlock("One Small Step - Cleanup companion JSFXs",-1);
-- cleanupCompanionFXs();
end

function atLoop()
Expand All @@ -469,16 +533,25 @@ return {
NoteLenMode = NoteLenMode,
NoteLenModifier = NoteLenModifier,

NoteLenDefs = NoteLenDefs,
AugmentedDiminishedDefs = AugmentedDiminishedDefs,

--Functions
setMode = setMode,
getMode = getMode,
setInputMode = setInputMode,
getInputMode = getInputMode,

setNoteLenMode = setNoteLenMode,
getNoteLenMode = getNoteLenMode,

setTupletDivision = setTupletDivision,
getTupletDivision = getTupletDivision,

getNoteADFactor = getNoteADFactor,
setNoteADFactor = setNoteADFactor,

getNoteADSign = getNoteADSign,
setNoteADSign = setNoteADSign,

getNoteLenModifier = getNoteLenModifier,
setNoteLenModifier = setNoteLenModifier,
getNoteLenModifierFactor = getNoteLenModifierFactor,
Expand Down

0 comments on commit d1f1b8a

Please sign in to comment.