Skip to content
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
53 changes: 50 additions & 3 deletions MIDI Editor/talagan_OneSmallStep.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--[[
@description One Small Step : Alternative Step Input
@version 0.9.21
@version 0.9.22
@author Ben 'Talagan' Babut
@license MIT
@metapackage
@changelog
- [Cosmetics] Adapted to ImGui 0.10
- [Feature] Note length "auto" mode (thanks, smandrap !)
@provides
[main=main,midi_editor] .
[main=main,midi_editor] talagan_OneSmallStep/actions/talagan_OneSmallStep Change input mode - (MIDI).lua
Expand All @@ -22,6 +22,7 @@
[main=main,midi_editor] talagan_OneSmallStep/actions/talagan_OneSmallStep Change note len param source.lua > talagan_OneSmallStep/actions/talagan_OneSmallStep Change note len param source - OSS.lua
[main=main,midi_editor] talagan_OneSmallStep/actions/talagan_OneSmallStep Change note len param source.lua > talagan_OneSmallStep/actions/talagan_OneSmallStep Change note len param source - ItemConf.lua
[main=main,midi_editor] talagan_OneSmallStep/actions/talagan_OneSmallStep Change note len param source.lua > talagan_OneSmallStep/actions/talagan_OneSmallStep Change note len param source - ProjectGrid.lua
[main=main,midi_editor] talagan_OneSmallStep/actions/talagan_OneSmallStep Change note len param source.lua > talagan_OneSmallStep/actions/talagan_OneSmallStep Change note len param source - Auto.lua
[main=main,midi_editor] talagan_OneSmallStep/actions/talagan_OneSmallStep Change note len modifier - (MIDI).lua
[main=main,midi_editor] talagan_OneSmallStep/actions/talagan_OneSmallStep Change note len modifier.lua > talagan_OneSmallStep/actions/talagan_OneSmallStep Change note len modifier - Straight.lua
[main=main,midi_editor] talagan_OneSmallStep/actions/talagan_OneSmallStep Change note len modifier.lua > talagan_OneSmallStep/actions/talagan_OneSmallStep Change note len modifier - Triplet.lua
Expand Down Expand Up @@ -92,7 +93,7 @@
@stevie, @hipox, @MartinTL, @henu, @Thonex, @smandrap, @SoaSchas, @daodan, @inthevoid, @dahya, @User41, @Spookye, @R.Cato, @samlletas
--]]

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

PATH = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]]
Expand Down Expand Up @@ -577,16 +578,48 @@ function ConfSourceMiniBar()
TT('Note Length conf : One Small Step\n\nUse the params aside.')
SL()

local is_midi_editor_focused = false
if nlm == D.NoteLenParamSource.Auto then
local behaviour = S.getSetting("AutoNoteLengthModeTargetsMidiEditorWhen")
if behaviour == D.AutoNoteLengthModeTargetsMidiEditorWhen.Focused then
is_midi_editor_focused = F.IsActiveMidiEditorFocused()
else
is_midi_editor_focused = (reaper.MIDIEditor_GetActive() ~= nil)
end
end

if ButtonGroupImageButton('note_len_mode_pgrid', nlm == D.NoteLenParamSource.ProjectGrid) then
S.setNoteLenParamSource(D.NoteLenParamSource.ProjectGrid)
end

if nlm == D.NoteLenParamSource.Auto and not is_midi_editor_focused then
local draw_list = ImGui.GetWindowDrawList(ctx)
local px, py = ImGui.GetItemRectMin(ctx)
local px2, py2 = ImGui.GetItemRectMax(ctx)
ImGui.DrawList_AddRect(draw_list, px-1,py-1,px2+1,py2+1, ColorSets.Blue.on)
end

TT( "Note Length conf : Project\n\nUse the project's grid conf.")
SL()

if ButtonGroupImageButton('note_len_mode_inote', nlm == D.NoteLenParamSource.ItemConf) then
S.setNoteLenParamSource(D.NoteLenParamSource.ItemConf)
end

if nlm == D.NoteLenParamSource.Auto and is_midi_editor_focused then
local draw_list = ImGui.GetWindowDrawList(ctx)
local px, py = ImGui.GetItemRectMin(ctx)
local px2, py2 = ImGui.GetItemRectMax(ctx)
ImGui.DrawList_AddRect(draw_list, px-1,py-1,px2+1,py2+1, ColorSets.Blue.on)
end

TT( "Note Length conf : MIDI Item\n\nUse the MIDI item's own conf.\n\n('Notes' at the bottom of the MIDI editor)")
SL()

if ButtonGroupImageButton('note_len_mode_auto', nlm == D.NoteLenParamSource.Auto) then
S.setNoteLenParamSource(D.NoteLenParamSource.Auto)
end
TT( "Note Length conf : Auto\n\nUse the project's grid or the current item's conf, depending on what's focused.")
end

-- MINIBAR : Note length
Expand Down Expand Up @@ -1381,6 +1414,16 @@ function SettingsPanel()
S.setSetting("SelectInputNotes", not curval)
end

ImGui.AlignTextToFramePadding(ctx)
ImGui.TextColored(ctx, 0xFFA0F0FF, "Auto")
SL()
ImGui.Text(ctx, "note length mode uses the Item's configuration when the ME is")
SL()
SettingComboBox("AutoNoteLengthModeTargetsMidiEditorWhen", "", "", 100)
SL()
ImGui.Text(ctx, "else it uses the Project's grid")


curval = S.getSetting("AlwaysFocusMEOnLaunch")
---@diagnostic disable-next-line: param-type-mismatch
if ImGui.Checkbox(ctx, "Always focus the MIDI Editor on launch", curval) then
Expand Down Expand Up @@ -1737,6 +1780,10 @@ local function UiLoop()
ItemGridLabel(ctx,take); SL()
XSeparator(); SL()
NoteLenOptions(true)
elseif nlm == D.NoteLenParamSource.Auto then
ItemGridLabel(ctx,take); SL()
XSeparator(); SL()
NoteLenOptions(true)
end

ImGui.PopStyleVar(ctx,3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ local _,fname,_,_,_,_,v,ctxs = reaper.get_action_context()
local param = fname:match("%- %(([^%s]*)%)%.lua$");

if (param == "MIDI") and (ctxs:match("^midi:")) then
local vcount = 3
local vcount = 4
local mn = math.floor(0.5 + (v / 127.0) * (vcount-1)) + 1

if(mn == 1) then param = "OSS"
elseif(mn == 2) then param = "ProjectGrid"
else param = "ItemConf"
elseif(mn == 3) then param = "ItemConf"
else param = "Auto"
end

S.setNoteLenParamSource(D.NoteLenParamSource[param])
Expand Down
10 changes: 9 additions & 1 deletion MIDI Editor/talagan_OneSmallStep/classes/modules/defines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ local NoteLenDefs = {
local NoteLenParamSource = {
OSS = 0,
ProjectGrid = 1,
ItemConf = 2
ItemConf = 2,
Auto = 3
}

local InputMode = {
Expand Down Expand Up @@ -52,6 +53,11 @@ local EditMode = {
Stuff = "Stuff"
}

local AutoNoteLengthModeTargetsMidiEditorWhen = {
Focused = "Focused",
Open = "Open"
}

local ActionTriggers = {
Commit = { action = "Commit", back = false },
CommitBack = { action = "Commit", back = true },
Expand Down Expand Up @@ -170,6 +176,8 @@ return {
ModifierKeyCombinations = ModifierKeyCombinations,
ModifierKeyCombinationLookup = ModifierKeyCombinationLookup,

AutoNoteLengthModeTargetsMidiEditorWhen = AutoNoteLengthModeTargetsMidiEditorWhen,

ModifierPedals = ModifierPedals,
ModifierPedalLookup = ModifierPedalLookup
}
Expand Down
2 changes: 2 additions & 0 deletions MIDI Editor/talagan_OneSmallStep/classes/modules/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ local SettingDefs = {
AutoScrollArrangeView = { type = "bool", default = true },
AlwaysFocusMEOnLaunch = { type = "bool", default = false},

AutoNoteLengthModeTargetsMidiEditorWhen = { type = "string", default = D.AutoNoteLengthModeTargetsMidiEditorWhen.Focused, inclusion = { D.AutoNoteLengthModeTargetsMidiEditorWhen.Focused, D.AutoNoteLengthModeTargetsMidiEditorWhen.Open } },

AllowKeyEventNavigation = { type = "bool", default = false },

Disarmed = { type = "bool", default = false },
Expand Down
15 changes: 13 additions & 2 deletions MIDI Editor/talagan_OneSmallStep/classes/modules/time.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

local D = require "modules/defines"
local S = require "modules/settings"
local F = require "modules/focus"

local function bool2sign(b)
return ((b == true) and (1) or (-1))
Expand Down Expand Up @@ -127,9 +128,19 @@ local function ResolveNoteLenQN(take)
_, measureStartQN, measureEndQN = reaper.TimeMap_GetMeasureInfo(0, cursorMes - 1)
end

local is_midi_editor_focused = false
if nlm == D.NoteLenParamSource.Auto then
local behaviour = S.getSetting("AutoNoteLengthModeTargetsMidiEditorWhen")
if behaviour == D.AutoNoteLengthModeTargetsMidiEditorWhen.Focused then
is_midi_editor_focused = F.IsActiveMidiEditorFocused()
else
is_midi_editor_focused = (reaper.MIDIEditor_GetActive() ~= nil)
end
end

if nlm == D.NoteLenParamSource.OSS then
return S.getNoteLenQN() * S.getNoteLenModifierFactor()
elseif nlm == D.NoteLenParamSource.ProjectGrid then
elseif nlm == D.NoteLenParamSource.ProjectGrid or (nlm == D.NoteLenParamSource.Auto and not is_midi_editor_focused) then

local _, division, swingmode, swing = reaper.GetSetProjectGrid(0, false)
local noteLenQN = division * 4
Expand All @@ -153,7 +164,7 @@ local function ResolveNoteLenQN(take)

return baselen * S.getNoteLenQN() * S.getNoteLenModifierFactor()

else
elseif nlm == D.NoteLenParamSource.ItemConf or (nlm == D.NoteLenParamSource.Auto and is_midi_editor_focused) then
local gridLenQN, swing, noteLenQN = reaper.MIDI_GetGrid(take);
local multFactor = S.getNoteLenQN()

Expand Down
Loading