Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update OneSmallStep v0.1 > v0.8 #1316

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions MIDI Editor/talagan_OneSmallStep Change note len mode.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- @noindex
-- @author Ben 'Talagan' Babut
-- @license MIT
-- @description This is part of One Small Step

package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path;

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);
elseif mode == 'ItemConf' then
engine_lib.setNoteLenMode(engine_lib.NoteLenMode.ItemConf);
elseif mode == 'ProjectGrid' then
engine_lib.setNoteLenMode(engine_lib.NoteLenMode.ProjectGrid);
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ elseif modifier == 'Dotted' then
engine_lib.setNoteLenModifier(engine_lib.NoteLenModifier.Dotted);
elseif modifier == 'Straight' then
engine_lib.setNoteLenModifier(engine_lib.NoteLenModifier.Straight);
end
elseif modifier == 'Tuplet' then
engine_lib.setNoteLenModifier(engine_lib.NoteLenModifier.Tuplet);
end
300 changes: 267 additions & 33 deletions MIDI Editor/talagan_OneSmallStep.lua

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions MIDI Editor/talagan_OneSmallStep/images/note_len_mode_igrid.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\x2E\x23\x00\x00\x2E\x23\x01\x78\xA5\x3F\x76\x00\x00\x00\x99\x49\x44\x41\x54\x48\x89\xED\x95\x4B\x0A\xC0\x20\x0C\x05\x63\xE9\x36\x8B\x9E\xA5\xF7\x3F\z
\x53\x17\xEF\x00\xE9\xA6\x2D\x45\x53\x09\x7E\x50\xAA\xB3\x53\x02\xA3\x21\xBC\x38\x11\xA1\x16\x2C\x4D\xAC\x53\xDC\x9D\x18\x80\x00\x28\x56\x67\x16\xD7\x60\x3C\xB1\z
\xF3\x03\x04\x40\x95\x44\x61\x66\xF7\x3E\xAF\xDA\x63\x94\x3B\xF9\xB8\x4F\xAD\xEB\xA8\xD5\x1A\x57\xFB\x1D\x33\x17\x13\x8F\x37\xD5\x53\x9C\x8B\x10\xD1\xDE\x42\x4C\z
\x44\xB4\x59\x8A\x82\x00\x89\x24\xD7\xB3\x79\xFC\x14\x4A\xA1\x74\x72\x99\x49\x6A\xB5\x75\xE7\xC6\x08\x7E\xAC\xA5\xD3\xAB\xC5\xD9\xC2\x9B\x1A\xC3\x75\x58\x8A\x4C\z
\x59\x5D\x83\xDF\x04\xC8\x14\xF7\x27\x3E\x01\x77\x0D\x34\xA3\x25\xE0\xE4\x98\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82"
;
24 changes: 24 additions & 0 deletions MIDI Editor/talagan_OneSmallStep/images/note_len_mode_oss.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- @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\x2E\x23\x00\x00\x2E\x23\x01\x78\xA5\x3F\x76\x00\x00\x02\x4C\x49\x44\x41\x54\x48\x89\xE5\xD6\x4B\x88\x8F\x51\x18\xC7\xF1\xCF\xA0\xD9\x18\x2B\x97\x9A\z
\x18\x97\x58\x91\xA1\x66\x61\x87\x66\xB2\x20\xAC\x26\x45\x6C\x28\x8A\xA9\x91\x30\x25\x11\x93\x72\x59\x8C\x1A\x53\xCA\x65\x37\x2B\x16\x2E\x53\x28\x97\x98\x94\x88\z
\x85\x59\x52\x6E\x23\x93\x26\x3B\xCA\x24\x63\x71\xCE\x34\xEF\xFF\xCC\xFF\x9D\xFF\x8B\x32\x0B\xBF\xCD\xF3\x9E\xE7\x9C\xF7\x7C\xDF\xF7\x39\xCF\x79\xCE\xA9\x1A\x1E\z
\x1E\x36\x11\x9A\x34\x21\xD4\xFF\x12\x3C\x25\x75\x0C\x0D\x0D\x8D\x37\x7E\x26\xD6\xA3\x01\xB5\xA8\xC2\x27\xBC\xC0\x4D\x7C\xCE\x7B\xB1\xBA\xBA\x7A\x7C\x70\x8E\xE6\z
\xA2\x13\x1B\x2B\x8C\xEB\x41\x0B\xDE\x55\x9A\xB0\x48\xA8\x0F\xC7\x89\x2A\x41\x09\xD1\x78\x8B\xBD\x7F\x0B\xBE\x88\x76\x3C\x29\x00\xCD\xAA\x03\x67\xFF\x14\x7C\x08\z
\x3B\xB0\x02\x5F\x2A\x80\xBE\xE3\x69\xB4\x23\x6A\xC5\xFE\xDF\x05\x2F\xC1\x09\xAC\xC5\x57\xAC\xAB\x00\xEE\x8E\x1F\xD8\x9A\xF8\xCF\x60\xF1\xEF\x80\x2F\xE1\x0D\x6E\z
\x63\x4F\x05\x28\xF4\x46\x7B\xC1\xD8\xCC\x3E\x5A\x14\x5C\x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EF\x16\xAA\xDC\x54\xA1\xAC\x76\x1A\xDD\xCF\x07\x84\x65\xCA\x55\xDE\x1A\xA7\x5A\x24\x9C\x54\x0B\x63\xFB\x15\x5E\x0B\xE5\z
\x74\x86\x90\x13\x35\x78\x8C\x6D\xC2\xC9\x56\xA2\x74\x8D\x8B\x82\x47\x34\x5B\x88\x42\xA3\xB0\x6F\xAB\x84\x8C\x7D\x20\xDC\x56\xFA\xF3\x5E\xAC\x08\xFE\x57\xFA\xFF\z
\x2E\xF4\x13\x06\xFE\x05\xC3\xB2\x80\x27\x57\x8C\xEE\x16\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82"
;
14 changes: 14 additions & 0 deletions MIDI Editor/talagan_OneSmallStep/images/note_len_mode_pgrid.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- @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\x2E\x23\x00\x00\x2E\x23\x01\x78\xA5\x3F\x76\x00\x00\x00\xC2\x49\x44\x41\x54\x48\x89\xED\x95\x5D\x0E\xC2\x20\x10\x84\x67\x8C\xAF\xFB\xE0\x5D\x3C\x82\z
\x5C\xD2\xAB\x78\x86\x1E\xC1\x33\xF8\xB0\x07\x58\x1F\xAC\x06\x5B\xBA\xE9\x0F\x58\x62\x3B\x09\x09\x90\x09\x1F\x2C\x64\xA0\x99\x61\x0D\x1D\x56\xA1\xEE\xE0\xEA\xC0\z
\xAA\x6A\xAA\x9A\xCD\x37\x1A\x5C\x42\xDB\x03\xB3\x1B\x20\xAA\x5A\x24\x51\x44\x84\xF1\xF8\x98\xDA\x4C\x62\xCE\x06\xE6\xE7\xFA\x2A\x2A\x75\x4A\x6D\xF9\x29\x22\xD9\z
\xC0\xDB\x7B\xD5\x3B\x78\x89\x2C\x6A\x77\x00\x97\x5F\x81\x01\x20\x90\x24\x80\x2B\x80\x9B\x67\xEC\x05\x88\x93\x5C\x9F\x9F\xA7\x9B\x42\x5F\x26\xB3\x53\xDB\x7D\x4C\z
\x02\x63\x59\x72\xBD\x4F\xD9\x00\x08\x9E\x71\x56\xA9\x9D\x3F\x37\xF0\xA5\x33\xC9\xC6\x5B\xA3\x77\xE2\x54\x3A\x45\x25\x9E\xBE\xCB\x01\xE5\x7E\x5C\xEE\xBD\xC6\x1A\z
\x95\xD5\x25\xF4\x17\x01\xB2\x83\xEB\x04\x3F\x01\x37\x8E\x40\x36\x92\x78\x44\xFC\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82"
;
15 changes: 15 additions & 0 deletions MIDI Editor/talagan_OneSmallStep/images/note_tuplet.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\xE2\x49\x44\x41\x54\x48\x89\xED\x96\x3D\x0A\xC2\x40\x10\x46\x5F\xC4\x76\x8A\x74\x01\xBB\x5C\z
\x21\xA5\x90\xCA\x1C\xC1\x1C\xC1\x33\xE4\x08\xE6\x0A\x39\x82\x5E\xC1\x2A\x60\xE9\x11\x4C\x27\xA4\x4B\x31\x07\x88\x45\x56\x10\x0C\xE8\xF8\x43\x0A\xF7\xAB\x76\x60\z
\x66\xDE\xCE\xC7\xB2\xBB\x41\xDF\xF7\x4C\xA1\xD9\x24\x54\x0F\xF6\x60\x0F\xF6\xE0\x4F\x34\xB7\x24\xAB\x6A\x0C\x9C\x5D\x58\x00\x31\xB0\x01\x0A\x11\x29\x2D\xBD\x4C\z
\x13\x8B\x48\x03\x64\x2E\x8C\x81\x13\x70\x70\x6B\x93\x46\x27\xBE\xB4\xED\xE8\xCB\xB1\x88\xA2\x00\x48\x80\x0E\xE8\x44\xA4\x52\xD5\x2D\xB0\x7F\xA1\xEE\x39\x18\xE0\z
\x58\xD7\x0F\xC9\x79\x9E\x03\xAC\x1D\xB8\x54\xD5\x04\x08\x6F\xE0\xB1\x9A\x65\x9A\x8E\x6E\xC6\x64\xB5\xAA\x86\x0C\x13\x97\x22\xD2\x01\x2B\x06\xBB\x13\x4B\x1F\x33\z
\x98\xE1\x20\x35\x22\x52\xB9\x38\x01\x1A\x06\x17\x4C\x0A\x2C\x1F\x01\x55\xDD\x39\x70\x71\x17\xC7\x40\xE6\x1C\xF8\x0D\xF8\x9B\xFA\xBF\x9B\xCB\x83\x3D\xD8\x83\x3D\z
\xF8\x6D\x5D\x01\x75\x01\x41\x78\x66\xDC\x48\x8D\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82"
;
119 changes: 99 additions & 20 deletions MIDI Editor/talagan_OneSmallStep/talagan_OneSmallStep Engine lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ local noteLenLookup = {
["1_64"] = {next="1_32", prec="1_64", qn=0.0625 }
};

local NoteLenMode = {
OSS=0,
ProjectGrid=1,
ItemConf=2
}

local InputMode = {
None=0,
Pedal=1,
Expand All @@ -31,23 +37,45 @@ local InputMode = {
local NoteLenModifier = {
Straight=0,
Dotted=1,
Triplet=2
Triplet=2,
Tuplet=3
}


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

-----------

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

-----------

local function setNoteLenMode(m)
reaper.SetExtState("OneSmallStep", "NoteLenMode", tostring(m), true)
end
local function getNoteLenMode()
return tonumber(reaper.GetExtState("OneSmallStep", "NoteLenMode")) or 0;
end

-----------

local function setTupletDivision(m)
reaper.SetExtState("OneSmallStep", "TupletDivision", tostring(m), true)
end
local function getTupletDivision()
return tonumber(reaper.GetExtState("OneSmallStep", "TupletDivision")) or 4;
end

-----------

local function setNoteLen(str)
-- Persist the param
reaper.SetExtState("OneSmallStep", "NoteLen", str, true);
end
local function getNoteLen()
Expand All @@ -58,13 +86,16 @@ local function getNoteLen()
return nl;
end

-----------

local function setNoteLenModifier(m)
reaper.SetExtState("OneSmallStep", "NoteLenModifier", tostring(m), true);
end
local function getNoteLenModifier()
return tonumber(reaper.GetExtState("OneSmallStep", "NoteLenModifier"));
end
local function getNoteLenModifierFactor()

local m = getNoteLenModifier();

if m == NoteLenModifier.Straight then
Expand All @@ -73,6 +104,9 @@ local function getNoteLenModifierFactor()
return 1.5;
elseif m == NoteLenModifier.Triplet then
return 2/3.0;
elseif m == NoteLenModifier.Tuplet then
local div = getTupletDivision();
return 2.0/div;
end

return 1.0;
Expand All @@ -89,7 +123,8 @@ local function decreaseNoteLen()
end

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

return noteLenLookup[nl].qn;
end

Expand Down Expand Up @@ -170,18 +205,44 @@ local function TakeForEdition()
return nil
end

-- Commits the currently held notes into the take
local function commit(take, notes)

--[[
local grid_len, swing, note_len = reaper.MIDI_GetGrid(take);
local function resolveNoteLenQN(take)

if note_len == 0 then
note_len = grid_len;
local nlm = getNoteLenMode();

if nlm == NoteLenMode.OSS then
return getNoteLenQN() * getNoteLenModifierFactor();
elseif nlm == NoteLenMode.ProjectGrid then

local _, qn, swing, _ = reaper.GetSetProjectGrid(0, false);

if swing == 3 then
-- Project Grid is set to "measure"
local pos = reaper.GetCursorPosition();
local posqn = reaper.TimeMap2_timeToQN(0, pos);
local posm = reaper.TimeMap_QNToMeasures(0, posqn);

local _, measureStart, measureEnd = reaper.TimeMap_GetMeasureInfo(0, posm - 1);
return measureEnd - measureStart;
else
return qn * 4;
end

else
local grid_len, swing, note_len = reaper.MIDI_GetGrid(take);

if note_len == 0 then
note_len = grid_len;
end

return note_len;
end
]]--
end

local note_len = getNoteLenQN() * getNoteLenModifierFactor();
-- Commits the currently held notes into the take
local function commit(take, notes)

local note_len = resolveNoteLenQN(take);

local noteStartTime = reaper.GetCursorPosition()
local noteStartQN = reaper.TimeMap2_timeToQN(0, noteStartTime)
Expand All @@ -203,6 +264,20 @@ local function commit(take, notes)
reaper.UpdateItemInProject(mediaItem)
reaper.SetEditCurPos(noteEndTime, false, false);
reaper.MarkTrackItemsDirty(track, mediaItem)

-- Grow the midi item
local itemStartTime = reaper.GetMediaItemInfo_Value(mediaItem, "D_POSITION")
local itemLength = reaper.GetMediaItemInfo_Value(mediaItem, "D_LENGTH")
local itemEndTime = itemStartTime + itemLength;

if(itemEndTime >= noteEndTime) then
return
end

local itemStartQN = reaper.TimeMap2_timeToQN(0, itemStartTime)
local itemEndQN = reaper.TimeMap2_timeToQN(0, noteEndTime)

reaper.MIDI_SetItemExtents(mediaItem, itemStartQN, itemEndQN)
end

--------------------------------------------------------------------
Expand Down Expand Up @@ -316,15 +391,15 @@ local function listenToEvents(called_from_action)
local oss_state = helper_lib.oneSmallStepState(track);

if mode == InputMode.Pedal then
if oss_state.pedalActivity > 0 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);
end

elseif mode == InputMode.Action then
if called_from_action then
reaper.Undo_BeginBlock();
Expand All @@ -351,14 +426,11 @@ local function listenToEvents(called_from_action)
end
end

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

Expand Down Expand Up @@ -394,12 +466,19 @@ end
return {
-- Enums
InputMode = InputMode,
NoteLenMode = NoteLenMode,
NoteLenModifier = NoteLenModifier,

--Functions
setMode = setMode,
getMode = getMode,

setNoteLenMode = setNoteLenMode,
getNoteLenMode = getNoteLenMode,

setTupletDivision = setTupletDivision,
getTupletDivision = getTupletDivision,

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