Skip to content

Commit

Permalink
Update OneSmallStep 0.9.15 > 0.9.16
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTalagan committed Feb 25, 2025
1 parent c94f9cd commit 6e5d0fd
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 86 deletions.
130 changes: 100 additions & 30 deletions MIDI Editor/talagan_OneSmallStep.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--[[
@description One Small Step : Alternative Step Input
@version 0.9.15
@version 0.9.16
@author Ben 'Talagan' Babut
@license MIT
@metapackage
Expand Down Expand Up @@ -57,7 +57,7 @@
@screenshot
https://stash.reaper.fm/48269/oss_094.png
@changelog
- [Feature] [Experimental] Markup Articulation Manager
- [Feature] Add support for pedals as step back modifiers
@about
# Purpose
Expand Down Expand Up @@ -88,7 +88,7 @@
--]]

VERSION = "0.9.15"
VERSION = "0.9.16"
DOC_URL = "https://bentalagan.github.io/onesmallstep-doc/index.html?ver=" .. VERSION

PATH = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]]
Expand Down Expand Up @@ -129,6 +129,7 @@ if not CheckReapack("CF_ShellExecute", "SWS", "SWS/S&M Ex
-- Inner requirements

local E = require "engine_lib"
local H = require "helper_lib"
local DBG = require "modules/debugger"

local S = E.S
Expand All @@ -138,14 +139,16 @@ local TGT = E.TGT
local F = E.F
local ED = E.ED
local ART = E.ART
local MOD = E.MOD

-- Get the debugger setting at launch
local DEBUGGER_IS_ON = S.getSetting("UseDebugger")

-------------------------------
-- ImGui Backward compatibility

dofile(reaper.GetResourcePath() .. '/Scripts/ReaTeam Extensions/API/imgui.lua')('0.8.7')
package.path = reaper.ImGui_GetBuiltinPath() .. '/?.lua;' .. package.path
local ImGui = require 'imgui' '0.8.7'

-------------------------------

Expand Down Expand Up @@ -989,8 +992,29 @@ function SettingComboBox(setting, pre_label, tooltip, width)
TT(tooltip)
end

local function ResolveStepBackPedalState()
local ccnum = S.getSetting("StepBackModifierPedal")

if ccnum == -1 then return end

local track = nil
local take = TGT.TakeForEdition()

if take then track = reaper.GetMediaItemTake_Track(take)
else track = TGT.TrackForEditionIfNoItemFound()
end

if not track then return false end

local oss_state = H.oneSmallStepState(track)
return H.isModifierPedalDown(oss_state, ccnum)
end

function TargetModeInfo()
local currentop = ED.ResolveOperationMode()
local back_pedal = ResolveStepBackPedalState()

local currentop = ED.ResolveOperationMode()
local back_modifier = back_pedal or MOD.IsStepBackModifierKeyPressed()

local _TT = function(msg, is_alt, alternative)
msg = msg .. "\n\n" .. "Click to set/move/remove operation marker\n\n"
Expand All @@ -1004,53 +1028,53 @@ function TargetModeInfo()

if currentop.mode == "Insert" then
if currentop.use_alt then
if currentop.back then
reaper.ImGui_Image(ctx, getImage("indicator_compress"),20,20); _TT("Compress notes between marker and edit cursor", true, "Insert"); SL();
if back_modifier then
ImGui.Image(ctx, getImage("indicator_compress"),20,20); _TT("Compress notes between marker and edit cursor", true, "Insert"); SL();
else
reaper.ImGui_Image(ctx, getImage("indicator_stretch"),20,20); _TT("Stretch notes between marker and edit cursor", true, "Insert"); SL();
ImGui.Image(ctx, getImage("indicator_stretch"),20,20); _TT("Stretch notes between marker and edit cursor", true, "Insert"); SL();
end
else
if currentop.back then
reaper.ImGui_Image(ctx, getImage("indicator_insert_back"),20,20); _TT("Insert back (delete and shift)", false, "Compress"); SL();
if back_modifier then
ImGui.Image(ctx, getImage("indicator_insert_back"),20,20); _TT("Insert back (delete and shift)", false, "Compress"); SL();
else
reaper.ImGui_Image(ctx, getImage("indicator_insert_forward"),20,20); ; _TT("Insert (add notes and shift)", false, "Stretch"); SL();
ImGui.Image(ctx, getImage("indicator_insert_forward"),20,20); ; _TT("Insert (add notes and shift)", false, "Stretch"); SL();
end
end
elseif currentop.mode == "Replace" then
if currentop.use_alt then
if currentop.back then
reaper.ImGui_Image(ctx, getImage("indicator_unstuff"),20,20); _TT("Stuff notes at the end of the zone between marker and edit cursor", true, "Replace"); SL();
if back_modifier then
ImGui.Image(ctx, getImage("indicator_unstuff"),20,20); _TT("Stuff notes at the end of the zone between marker and edit cursor", true, "Replace"); SL();
else
reaper.ImGui_Image(ctx, getImage("indicator_stuff"),20,20); _TT("Unstuff notes at the end of the zone between marker and edit cursor", true, "Replace"); SL();
ImGui.Image(ctx, getImage("indicator_stuff"),20,20); _TT("Unstuff notes at the end of the zone between marker and edit cursor", true, "Replace"); SL();
end
else
if currentop.back then
reaper.ImGui_Image(ctx, getImage("indicator_replace_back"),20,20); SL(); _TT("Replace back (delete)", false, "Untuff"); SL();
if back_modifier then
ImGui.Image(ctx, getImage("indicator_replace_back"),20,20); SL(); _TT("Replace back (delete)", false, "Untuff"); SL();
else
reaper.ImGui_Image(ctx, getImage("indicator_replace_forward"),20,20); SL(); _TT("Replace (add notes and remove/patch existing)", false, "Stuff"); SL();
ImGui.Image(ctx, getImage("indicator_replace_forward"),20,20); SL(); _TT("Replace (add notes and remove/patch existing)", false, "Stuff"); SL();
end
end
elseif currentop.mode == "Navigate" then
if currentop.back then
reaper.ImGui_Image(ctx, getImage("indicator_navigate_back"),20,20); SL(); TT("Navigate backward") SL();
if back_modifier then
ImGui.Image(ctx, getImage("indicator_navigate_back"),20,20); SL(); TT("Navigate backward") SL();
else
reaper.ImGui_Image(ctx, getImage("indicator_navigate_forward"),20,20); SL(); TT("Navigate forward") SL();
ImGui.Image(ctx, getImage("indicator_navigate_forward"),20,20); SL(); TT("Navigate forward") SL();
end
elseif currentop.mode == "Repitch" then
if currentop.back then
reaper.ImGui_Image(ctx, getImage("indicator_repitch_back"),20,20); SL(); TT("Write back (selective delete") SL();
if back_modifier then
ImGui.Image(ctx, getImage("indicator_repitch_back"),20,20); SL(); TT("Write back (selective delete") SL();
else
reaper.ImGui_Image(ctx, getImage("indicator_repitch_forward"),20,20); SL(); TT("Write (add notes)") SL();
ImGui.Image(ctx, getImage("indicator_repitch_forward"),20,20); SL(); TT("Write (add notes)") SL();
end
else
if currentop.back then
reaper.ImGui_Image(ctx, getImage("indicator_write_back"),20,20); SL(); TT("Write back (selective delete") SL();
if back_modifier then
ImGui.Image(ctx, getImage("indicator_write_back"),20,20); SL(); TT("Write back (selective delete") SL();
else
reaper.ImGui_Image(ctx, getImage("indicator_write_forward"),20,20); SL(); TT("Write (add notes)") SL();
ImGui.Image(ctx, getImage("indicator_write_forward"),20,20); SL(); TT("Write (add notes)") SL();
end
end

if reaper.ImGui_IsItemClicked(ctx) then
if ImGui.IsItemClicked(ctx) then
MK.setOperationMarkerAtCurrentPos()
end

Expand Down Expand Up @@ -1160,7 +1184,6 @@ function ClearConflictingModifierKeys()
end

function StepBackModifierKeyComboBox(callback)

local setting = "StepBackModifierKey"
local modkey = D.ModifierKeyLookup[S.getSetting(setting)] or {};
local combo_items = D.ModifierKeys;
Expand Down Expand Up @@ -1198,6 +1221,50 @@ function StepBackModifierKeyComboBox(callback)
reaper.ImGui_TextColored(ctx, 0xFFA0F0FF, "Back Operation")
end

function StepBackModifierPedalComboBox()
local setting = "StepBackModifierPedal"
local modifier = D.ModifierPedalLookup[S.getSetting(setting)] or {}
local combo_items = D.ModifierPedals
local label = modifier.name
local curval = modifier.ccnum

ImGui.PushStyleVar(ctx, ImGui.StyleVar_FramePadding, 5, 3.5)
ImGui.SetCursorPosY(ctx, ImGui.GetCursorPosY(ctx))
ImGui.PushID(ctx, setting)

ImGui.SetNextItemWidth(ctx, 160);
if ImGui.BeginCombo(ctx, '', label) then
for i,v in ipairs(combo_items) do
local is_selected = (curval == v.ccnum)

if is_selected then
ImGui.SetItemDefaultFocus(ctx)
end

if ImGui.Selectable(ctx, v.name, is_selected) then
S.setSetting(setting, v.ccnum)
ClearConflictingModifierKeys()
end
end
ImGui.EndCombo(ctx)
end
ImGui.PopStyleVar(ctx,1);
ImGui.PopID(ctx);

if S.getSetting(setting) == -1 then
SL()
ImGui.Text(ctx, "defined as pedal modifier for")
else
SL()
ImGui.TextColored(ctx, 0x9090FFFF, "+ sustain pedal")
SL()
ImGui.Text(ctx, "performs")
end

SL()
ImGui.TextColored(ctx, 0xFFA0F0FF, "Back Operation")
end


function EditModeComboBox(editModeName, callback)

Expand Down Expand Up @@ -1267,8 +1334,6 @@ function RepitchModeComboBox()
reaper.ImGui_PopStyleVar(ctx,1);
end



function SettingsPanel()
if reaper.ImGui_BeginTabBar(ctx, 'settings_tab_bar', reaper.ImGui_TabBarFlags_None()) then
reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Tab(), 0x00000000);
Expand Down Expand Up @@ -1397,13 +1462,18 @@ function SettingsPanel()
if reaper.ImGui_BeginTabItem(ctx, 'Controls') then
ImGui_VerticalSpacer(ctx,5);

ImGui.SeparatorText(ctx, "Key modifiers")
StepBackModifierKeyComboBox()
EditModeComboBox("Write")
EditModeComboBox("Navigate")
EditModeComboBox("Insert")
EditModeComboBox("Replace")
EditModeComboBox("Repitch")

ImGui.SeparatorText(ctx, "Pedal Modifiers")
StepBackModifierPedalComboBox()

ImGui.SeparatorText(ctx, "UI options")
local curval = S.getSetting("HideEditModeMiniBar");
if reaper.ImGui_Checkbox(ctx, "Hide edit mode mini bar", curval) then
S.setSetting("HideEditModeMiniBar", not curval);
Expand Down
36 changes: 27 additions & 9 deletions MIDI Editor/talagan_OneSmallStep/One Small Step Helper.jsfx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
noindex: true
desc: One Small Step Helper
version: 0.2
version: 0.3
author: Ben 'Talagan' Babut

<?
<?
note_buffer_size = 32; // MAX number of simultaneously held notes
note_slider_offset = 10; // Offset for note sliders (start at)
DBG = 0; // Show / Hide sliders in the JSFX window
Expand All @@ -13,11 +13,17 @@ author: Ben 'Talagan' Babut
dbg = (DBG == 1)?(""):("-");

printf("slider1:0<0,1,0.001> %sSustain Pedal Activity\n", dbg);
printf("slider2:0<0,127,1> %sHeld note count\n", dbg);
printf("slider2:0<0,1,0.001> %sCC65 Pedal Activity\n", dbg);
printf("slider3:0<0,1,0.001> %sCC66 Pedal Activity\n", dbg);
printf("slider4:0<0,1,0.001> %sCC67 Pedal Activity\n", dbg);
printf("slider5:0<0,1,0.001> %sCC68 Pedal Activity\n", dbg);
printf("slider6:0<0,1,0.001> %sCC69 Pedal Activity\n", dbg);

printf("slider7:0<0,127,1> %sHeld note count\n", dbg);

ni = 0;
while(ni < note_buffer_size) (

// Generate sliders for held notes
printf("slider%d:<0,127,1> %sNote %d Pitch\n", note_slider_offset + 4*ni + 0, dbg, ni);
printf("slider%d:<0,15,1> %sNote %d Channel\n", note_slider_offset + 4*ni + 1, dbg, ni);
Expand Down Expand Up @@ -118,11 +124,19 @@ function addRemoveNoteFromBuffer(m1,m2,m3)
);

// Update note count
slider2 = note_cnt;
slider7 = note_cnt;
);

@block

function handlePedal(ccnum, slidernum, msg1, msg2, msg3) (
(msg1&$xF0==$xB0 && msg2 == ccnum && msg3 > 0) ?
slider(slidernum) = time_precise();

(msg1&$xF0==$xB0 && msg2 == ccnum && msg3 == 0) ?
slider(slidernum) = 0;
);

function main()
local(offset,msg1,msg2,msg3)
(
Expand All @@ -134,11 +148,15 @@ function main()
(msg1&$xF0==$x80) ?
addRemoveNoteFromBuffer(msg1,msg2,msg3);

(msg1&$xF0==$xB0 && msg2 == 64 && msg3 > 0) ?
slider1 = time_precise();
// Support for sustain pedal
handlePedal(64, 1, msg1, msg2, msg3);

(msg1&$xF0==$xB0 && msg2 == 64 && msg3 == 0) ?
slider1 = 0;
// Added support for other pedals
handlePedal(65, 2, msg1, msg2, msg3);
handlePedal(66, 3, msg1, msg2, msg3);
handlePedal(67, 4, msg1, msg2, msg3);
handlePedal(68, 5, msg1, msg2, msg3);
handlePedal(69, 6, msg1, msg2, msg3);

midisend(offset,msg1,msg2,msg3);
)
Expand Down
2 changes: 1 addition & 1 deletion MIDI Editor/talagan_OneSmallStep/classes/engine_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ local function listenToEvents()
-- Update manager with new info from the helper JSFX
manager:updateActivity(track, oss_state);

local spmod = MOD.IsStepBackModifierKeyPressed();
local spmod = MOD.IsStepBackModifierKeyPressed() or helper_lib.isModifierPedalDown(oss_state, S.getSetting("StepBackModifierPedal"))
local pedal = manager:pullPedalTriggerForTrack(track);

manager:tryAdvancedCommitForTrack(track,
Expand Down
Loading

0 comments on commit 6e5d0fd

Please sign in to comment.