From 68d7fe6db59b09f61ff6dc0d842beafe982fc2a7 Mon Sep 17 00:00:00 2001 From: Kabraxist Date: Sun, 25 Feb 2024 13:02:10 +0300 Subject: [PATCH 1/5] ReaKS 0.3 Update --- MIDI Editor/ugurcanorcun_ReaKS.lua | 112 +++++++++++++++++++++++------ 1 file changed, 91 insertions(+), 21 deletions(-) diff --git a/MIDI Editor/ugurcanorcun_ReaKS.lua b/MIDI Editor/ugurcanorcun_ReaKS.lua index 91a6f74d5..cac6e2cc5 100644 --- a/MIDI Editor/ugurcanorcun_ReaKS.lua +++ b/MIDI Editor/ugurcanorcun_ReaKS.lua @@ -1,7 +1,8 @@ -- @description ReaKS - Keyswitch Articulation Manager -- @author Ugurcan Orcun --- @version 0.1 --- @changelog First commit +-- @version 0.3 +-- @changelog Added CC Renaming Helper /n Settings now saved between sessions /n Added ReaStash link to find more note names /n Minor layout changes +-- @link Forum Thread https://forum.cockos.com/showthread.php?t=288344 -- @about A small MIDI Editor tool for auto-inserting KeySwitch midi notes and managing note/cc names. dofile(reaper.GetResourcePath() .. '/Scripts/ReaTeam Extensions/API/imgui.lua')('0.8.7') @@ -21,6 +22,20 @@ Modal_Settings = false PPQ = reaper.SNM_GetIntConfigVar("miditicksperbeat", 960) +function SaveSettings() + reaper.SetExtState("ReaKS", "Setting_AutoupdateTextEvent", tostring(Setting_AutoupdateTextEvent), true) + reaper.SetExtState("ReaKS", "Setting_MaxColumns", tostring(Setting_MaxColumns), true) +end + +function LoadSettings() + local val + val = reaper.GetExtState("ReaKS", "Setting_AutoupdateTextEvent") + if val ~= "" then Setting_AutoupdateTextEvent = val == "true" end + + val = reaper.GetExtState("ReaKS", "Setting_MaxColumns") + if val ~= "" then Setting_MaxColumns = tonumber(val) end +end + function UpdateActiveTargets() ActiveMidiEditor = reaper.MIDIEditor_GetActive() or nil ActiveTake = reaper.MIDIEditor_GetTake(ActiveMidiEditor) or nil @@ -29,8 +44,7 @@ function UpdateActiveTargets() if ActiveTake ~= nil and ActiveTake ~= PreviousTake then Articulations = {} CC = {} - ParseNoteNamesFromTrack() - ParseCCNamesFromTrack() + RefreshGUI() end PreviousTake = ActiveTake @@ -62,8 +76,7 @@ function LoadNoteNames() Articulations = {} CC = {} reaper.MIDIEditor_LastFocused_OnCommand(40409, false) - ParseNoteNamesFromTrack() - ParseCCNamesFromTrack() + RefreshGUI() end function ParseNoteNamesFromTrack() @@ -90,6 +103,11 @@ function FocusToCCLane(i) reaper.BR_MIDI_CCLaneReplace(ActiveMidiEditor, 0, i) end +function RenameAliasCCLane() + reaper.MIDIEditor_LastFocused_OnCommand(40416, false) + RefreshGUI() +end + function SaveNoteNames() reaper.MIDIEditor_LastFocused_OnCommand(40410, false) end @@ -157,36 +175,87 @@ function GetActiveArticulationsAtPlayheadPosition() end end +function GetActiveArticulationsAtNoteSelection() + if ActiveTake == nil then return end + + ActivatedArticulations = {} + local earliestStartTime = math.huge + local latestEndTime = 0 + + local note = -2 + while note ~= -1 do + note = reaper.MIDI_EnumSelNotes(ActiveTake, note) + + local _, _, _, startppqpos, endppqpos, _, pitch, _ = reaper.MIDI_GetNote(ActiveTake, note) + if Articulations[pitch] ~= nil then + if startppqpos < earliestStartTime then earliestStartTime = startppqpos end + if endppqpos > latestEndTime then latestEndTime = endppqpos end + end + end + + --check all notes if it's an Articulation and if it's in the selected time range. If so, add it to the ActivatedArticulations list. + local midiNoteCount = reaper.FNG_CountMidiNotes(ActiveTake) + + for i = 0, midiNoteCount - 1 do + local _, _, _, startppqpos, endppqpos, _, pitch, _ = reaper.MIDI_GetNote(ActiveTake, i) + + if startppqpos <= latestEndTime and endppqpos >= earliestStartTime then + if Articulations[pitch] ~= nil then + ActivatedArticulations[pitch] = i + end + end + end +end + +function RefreshGUI() + UpdateTextEvents() + ParseNoteNamesFromTrack() + ParseCCNamesFromTrack() +end + -- UI Part local ctx = reaper.ImGui_CreateContext('ReaKS') local function loop() local visible, open = reaper.ImGui_Begin(ctx, 'ReaKS', true) if visible then - --TODO Make the settings modal - if Modal_Settings then - local val - - reaper.ImGui_BeginGroup(ctx) - reaper.ImGui_SeparatorText(ctx, "Settings") - if reaper.ImGui_Checkbox(ctx, "Autorefresh Text Values", Setting_AutoupdateTextEvent) then Setting_AutoupdateTextEvent = not Setting_AutoupdateTextEvent end - _, val = reaper.ImGui_SliderInt(ctx, "Max Rows", Setting_MaxColumns, 1, 10) - Setting_MaxColumns = val - reaper.ImGui_EndGroup(ctx) - end reaper.ImGui_BeginGroup(ctx) - reaper.ImGui_SeparatorText(ctx, "Note Names") + reaper.ImGui_SeparatorText(ctx, "Note Name Maps") if reaper.ImGui_Button(ctx, "Load") then LoadNoteNames() end reaper.ImGui_SameLine(ctx) if reaper.ImGui_Button(ctx, "Save") then SaveNoteNames() end reaper.ImGui_SameLine(ctx) if reaper.ImGui_Button(ctx, "Clear") then ClearNoteNames() end reaper.ImGui_SameLine(ctx) - if reaper.ImGui_Button(ctx, "Refresh") then UpdateTextEvents() ParseNoteNamesFromTrack() ParseCCNamesFromTrack()end + if reaper.ImGui_Button(ctx, "Refresh") then RefreshGUI()end reaper.ImGui_SameLine(ctx) if reaper.ImGui_Button(ctx, "Settings") then Modal_Settings = not Modal_Settings end reaper.ImGui_EndGroup(ctx) + --TODO Make the settings modal + if Modal_Settings then + local val + + reaper.ImGui_BeginGroup(ctx) + reaper.ImGui_SeparatorText(ctx, "Settings") + + if reaper.ImGui_Checkbox(ctx, "Autorefresh Text Events", Setting_AutoupdateTextEvent) then + Setting_AutoupdateTextEvent = not Setting_AutoupdateTextEvent + SaveSettings() + end + + _, val = reaper.ImGui_SliderInt(ctx, "Max Rows", Setting_MaxColumns, 1, 10) + if val ~= Setting_MaxColumns then + Setting_MaxColumns = val + SaveSettings() + end + + if reaper.ImGui_Button(ctx, "Rename Last Clicked CC Lane") then RenameAliasCCLane() end + if reaper.ImGui_Button(ctx, "Find More Note Names >>>") then reaper.CF_ShellExecute("https://stash.reaper.fm/tag/Key-Maps") end + + reaper.ImGui_EndGroup(ctx) + end + if ActiveTake == nil and Articulations ~= nil then reaper.ImGui_Text(ctx, "No active MIDI take is open in the MIDI editor.") else @@ -204,9 +273,7 @@ local function loop() end end end - reaper.ImGui_EndTable(ctx) - end if ActiveTake ~= nil and CC ~= nil then @@ -218,6 +285,8 @@ local function loop() end end + -- if reaper.ImGui_Button(ctx, "Test") then GetActiveArticulationsAtNoteSelection() end + reaper.ImGui_End(ctx) end @@ -229,4 +298,5 @@ local function loop() end end +LoadSettings() reaper.defer(loop) \ No newline at end of file From c1630437f1343180fd75e626107013c90730e571 Mon Sep 17 00:00:00 2001 From: Kabraxist Date: Tue, 27 Feb 2024 15:02:24 +0300 Subject: [PATCH 2/5] Version 0.5 --- MIDI Editor/ugurcanorcun_ReaKS.lua | 173 +++++++++++++++++------------ 1 file changed, 105 insertions(+), 68 deletions(-) diff --git a/MIDI Editor/ugurcanorcun_ReaKS.lua b/MIDI Editor/ugurcanorcun_ReaKS.lua index cac6e2cc5..13579efa5 100644 --- a/MIDI Editor/ugurcanorcun_ReaKS.lua +++ b/MIDI Editor/ugurcanorcun_ReaKS.lua @@ -1,9 +1,17 @@ -- @description ReaKS - Keyswitch Articulation Manager -- @author Ugurcan Orcun --- @version 0.3 --- @changelog Added CC Renaming Helper /n Settings now saved between sessions /n Added ReaStash link to find more note names /n Minor layout changes +-- @version 0.5 +-- @changelog +-- Added focused Track/Take name display +-- Added basic styling +-- Settings now saved between sessions +-- Refresh button fixed +-- Added cursor automove option +-- Minor layout changes -- @link Forum Thread https://forum.cockos.com/showthread.php?t=288344 --- @about A small MIDI Editor tool for auto-inserting KeySwitch midi notes and managing note/cc names. +-- @about +-- A small MIDI Editor tool for auto-inserting KeySwitch midi notes and managing note/cc names. +-- Find more info and example note name files at the forum thread. dofile(reaper.GetResourcePath() .. '/Scripts/ReaTeam Extensions/API/imgui.lua')('0.8.7') @@ -15,7 +23,22 @@ Articulations = {} CC = {} ActivatedArticulations = {} + +EnumThemeColors = { + -- Curiosity_Killed by Miaka on ColourLovers + E = 0x99173Cff, + D = 0x2E2633ff, + C = 0x555152ff, + B = 0xDCE9BEff, + A = 0xEFFFCDff +} + +ActiveTakeName = nil +ActiveTrackName = nil +ActiveTrackColor = 0xFFFFFFFF + Setting_AutoupdateTextEvent = true +Setting_MoveEditCursor = true Setting_MaxColumns = 2 Modal_Settings = false @@ -25,6 +48,7 @@ PPQ = reaper.SNM_GetIntConfigVar("miditicksperbeat", 960) function SaveSettings() reaper.SetExtState("ReaKS", "Setting_AutoupdateTextEvent", tostring(Setting_AutoupdateTextEvent), true) reaper.SetExtState("ReaKS", "Setting_MaxColumns", tostring(Setting_MaxColumns), true) + reaper.SetExtState("ReaKS", "Setting_MoveEditCursor", tostring(Setting_MoveEditCursor), true) end function LoadSettings() @@ -34,6 +58,9 @@ function LoadSettings() val = reaper.GetExtState("ReaKS", "Setting_MaxColumns") if val ~= "" then Setting_MaxColumns = tonumber(val) end + + val = reaper.GetExtState("ReaKS", "Setting_MoveEditCursor") + if val ~= "" then Setting_MoveEditCursor = val == "true" end end function UpdateActiveTargets() @@ -48,6 +75,15 @@ function UpdateActiveTargets() end PreviousTake = ActiveTake + + ActiveTakeName = reaper.GetTakeName(ActiveTake) + _, ActiveTrackName = reaper.GetTrackName(ActiveTrack) + +--[[ ActiveTrackColor = reaper.GetTrackColor(ActiveTrack) + if ActiveTrackColor == 0 then ActiveTrackColor = 0xFFFFFFFF + else + ActiveTrackColor = reaper.ImGui_ColorConvertNative(ActiveTrackColor) + end ]] end function UpdateTextEvents() @@ -79,8 +115,20 @@ function LoadNoteNames() RefreshGUI() end -function ParseNoteNamesFromTrack() +function SaveNoteNames() + reaper.MIDIEditor_LastFocused_OnCommand(40410, false) +end + +function ClearNoteNames() + reaper.MIDIEditor_LastFocused_OnCommand(40412, false) + Articulations = {} + CC = {} +end + +function ParseNoteNamesFromTake() if ActiveTake == nil then return end + + Articulations = {} for i = 0, 127 do local notename = reaper.GetTrackMIDINoteNameEx(0, ActiveTrack, i, 0) if notename ~= nil then @@ -89,8 +137,10 @@ function ParseNoteNamesFromTrack() end end -function ParseCCNamesFromTrack() +function ParseCCNamesFromTake() if ActiveTake == nil then return end + + CC = {} for i = 128, 255 do local ccname = reaper.GetTrackMIDINoteNameEx(0, ActiveTrack, i, 0) if ccname ~= nil then @@ -108,21 +158,10 @@ function RenameAliasCCLane() RefreshGUI() end -function SaveNoteNames() - reaper.MIDIEditor_LastFocused_OnCommand(40410, false) -end - -function ClearNoteNames() - reaper.MIDIEditor_LastFocused_OnCommand(40412, false) - Articulations = {} - CC = {} -end - function ToggleNote(noteNumber) - --Delete articulation if exists - if(ActivatedArticulations[noteNumber]) then + if(ActivatedArticulations[noteNumber]) then --Delete articulation if exists reaper.MIDI_DeleteNote(ActiveTake, ActivatedArticulations[noteNumber]) - else + else --Or insert articulation --Check if any midi notes are selected. Get earliest start time and latest end time if any selected notes. local _, noteCount = reaper.MIDI_CountEvts(ActiveTake) local earliestStartTime = math.huge @@ -138,7 +177,7 @@ function ToggleNote(noteNumber) end end - -- Start time -1 because giving time to Reaper to process the note + -- Start time offsetted by -1 ppq to activate the articulation before the note if earliestStartTime == math.huge then --Add articulation to playhead position local playheadPosition = reaper.GetCursorPosition() @@ -148,60 +187,29 @@ function ToggleNote(noteNumber) else --Add articulation to selected notes reaper.MIDI_InsertNote(ActiveTake, false, false, earliestStartTime - 1, latestEndTime, 0, noteNumber, 100, false) - end + reaper.SetEditCurPos(reaper.MIDI_GetProjTimeFromPPQPos(ActiveTake, earliestStartTime), Setting_MoveEditCursor, false) + end end if Setting_AutoupdateTextEvent then UpdateTextEvents() end end function GetActiveArticulationsAtPlayheadPosition() - if ActiveTake == nil then return end - - ActivatedArticulations = {} - local playheadPosition - - playheadPosition = reaper.GetPlayState() == 1 and reaper.GetPlayPosition() or reaper.GetCursorPosition() - playheadPosition = reaper.MIDI_GetPPQPosFromProjTime(ActiveTake, playheadPosition) - - local _, noteCount = reaper.MIDI_CountEvts(ActiveTake) - - for noteID = 1, noteCount do - local _, _, _, startppqpos, endppqpos, _, pitch, _ = reaper.MIDI_GetNote(ActiveTake, noteID - 1) - if startppqpos <= playheadPosition and endppqpos >= playheadPosition then - if Articulations[pitch] ~= nil then - ActivatedArticulations[pitch] = noteID - 1 - end - end - end -end - -function GetActiveArticulationsAtNoteSelection() if ActiveTake == nil then return end ActivatedArticulations = {} - local earliestStartTime = math.huge - local latestEndTime = 0 + local playheadPosition - local note = -2 - while note ~= -1 do - note = reaper.MIDI_EnumSelNotes(ActiveTake, note) - - local _, _, _, startppqpos, endppqpos, _, pitch, _ = reaper.MIDI_GetNote(ActiveTake, note) - if Articulations[pitch] ~= nil then - if startppqpos < earliestStartTime then earliestStartTime = startppqpos end - if endppqpos > latestEndTime then latestEndTime = endppqpos end - end - end - - --check all notes if it's an Articulation and if it's in the selected time range. If so, add it to the ActivatedArticulations list. - local midiNoteCount = reaper.FNG_CountMidiNotes(ActiveTake) - - for i = 0, midiNoteCount - 1 do - local _, _, _, startppqpos, endppqpos, _, pitch, _ = reaper.MIDI_GetNote(ActiveTake, i) - - if startppqpos <= latestEndTime and endppqpos >= earliestStartTime then + playheadPosition = reaper.GetPlayState() == 1 and reaper.GetPlayPosition() or reaper.GetCursorPosition() + playheadPosition = reaper.MIDI_GetPPQPosFromProjTime(ActiveTake, playheadPosition) + + local _, noteCount = reaper.MIDI_CountEvts(ActiveTake) + + for noteID = 1, noteCount do + local _, _, _, startppqpos, endppqpos, _, pitch, _ = reaper.MIDI_GetNote(ActiveTake, noteID - 1) + if startppqpos <= playheadPosition and endppqpos >= playheadPosition then if Articulations[pitch] ~= nil then - ActivatedArticulations[pitch] = i + ActivatedArticulations[pitch] = noteID - 1 end end end @@ -209,8 +217,24 @@ end function RefreshGUI() UpdateTextEvents() - ParseNoteNamesFromTrack() - ParseCCNamesFromTrack() + ParseNoteNamesFromTake() + ParseCCNamesFromTake() +end + +function StylingStart(ctx) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_WindowBg(), EnumThemeColors.D) + + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Button(), EnumThemeColors.C) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_ButtonActive(), EnumThemeColors.B) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_ButtonHovered(), EnumThemeColors.E) + + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_FrameBg(), EnumThemeColors.C) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_FrameBgActive(), EnumThemeColors.B) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_FrameBgHovered(), EnumThemeColors.A) +end + +function StylingEnd(ctx) + reaper.ImGui_PopStyleColor(ctx, 7) end -- UI Part @@ -219,6 +243,14 @@ local function loop() local visible, open = reaper.ImGui_Begin(ctx, 'ReaKS', true) if visible then + --StylingStart(ctx) + + if (ActiveTakeName ~= nil and ActiveTrackName ~= nil) then + --[[ reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Text(), ActiveTrackColor) ]] + reaper.ImGui_Text(ctx, ActiveTrackName .. " - " .. ActiveTakeName) + --[[ reaper.ImGui_PopStyleColor(ctx, 1) ]] + end + reaper.ImGui_BeginGroup(ctx) reaper.ImGui_SeparatorText(ctx, "Note Name Maps") if reaper.ImGui_Button(ctx, "Load") then LoadNoteNames() end @@ -244,6 +276,11 @@ local function loop() SaveSettings() end + if reaper.ImGui_Checkbox(ctx, "Automove Cursor ", Setting_MoveEditCursor) then + Setting_MoveEditCursor = not Setting_MoveEditCursor + SaveSettings() + end + _, val = reaper.ImGui_SliderInt(ctx, "Max Rows", Setting_MaxColumns, 1, 10) if val ~= Setting_MaxColumns then Setting_MaxColumns = val @@ -257,6 +294,7 @@ local function loop() end if ActiveTake == nil and Articulations ~= nil then + reaper.ImGui_Separator(ctx) reaper.ImGui_Text(ctx, "No active MIDI take is open in the MIDI editor.") else reaper.ImGui_SeparatorText(ctx, "Articulations") @@ -275,7 +313,7 @@ local function loop() end reaper.ImGui_EndTable(ctx) end - + if ActiveTake ~= nil and CC ~= nil then reaper.ImGui_SeparatorText(ctx, "Focus CC Lane") for i = 128, 255 do @@ -285,8 +323,7 @@ local function loop() end end - -- if reaper.ImGui_Button(ctx, "Test") then GetActiveArticulationsAtNoteSelection() end - +--StylingEnd(ctx) reaper.ImGui_End(ctx) end @@ -299,4 +336,4 @@ local function loop() end LoadSettings() -reaper.defer(loop) \ No newline at end of file +reaper.defer(loop) From e69b2f805073350d76b311516e8d510b2f9e631a Mon Sep 17 00:00:00 2001 From: Kabraxist Date: Tue, 27 Feb 2024 18:47:38 +0300 Subject: [PATCH 3/5] Take targeting fix --- MIDI Editor/ugurcanorcun_ReaKS.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MIDI Editor/ugurcanorcun_ReaKS.lua b/MIDI Editor/ugurcanorcun_ReaKS.lua index 13579efa5..f1132cdbf 100644 --- a/MIDI Editor/ugurcanorcun_ReaKS.lua +++ b/MIDI Editor/ugurcanorcun_ReaKS.lua @@ -76,8 +76,12 @@ function UpdateActiveTargets() PreviousTake = ActiveTake - ActiveTakeName = reaper.GetTakeName(ActiveTake) - _, ActiveTrackName = reaper.GetTrackName(ActiveTrack) + if ActiveTake ~= nil then + ActiveTakeName = reaper.GetTakeName(ActiveTake) + _, ActiveTrackName = reaper.GetTrackName(ActiveTrack) + else + ActiveTakeName = "No Take Selected" + end --[[ ActiveTrackColor = reaper.GetTrackColor(ActiveTrack) if ActiveTrackColor == 0 then ActiveTrackColor = 0xFFFFFFFF From b23fcab437de8229aa66d5570c45a3dd423fc4c2 Mon Sep 17 00:00:00 2001 From: Kabraxist Date: Fri, 1 Mar 2024 18:08:10 +0300 Subject: [PATCH 4/5] v0.6 Update --- MIDI Editor/ugurcanorcun_ReaKS.lua | 110 +++++++++++++++++------------ 1 file changed, 65 insertions(+), 45 deletions(-) diff --git a/MIDI Editor/ugurcanorcun_ReaKS.lua b/MIDI Editor/ugurcanorcun_ReaKS.lua index f1132cdbf..f81c8d5ed 100644 --- a/MIDI Editor/ugurcanorcun_ReaKS.lua +++ b/MIDI Editor/ugurcanorcun_ReaKS.lua @@ -1,13 +1,10 @@ -- @description ReaKS - Keyswitch Articulation Manager -- @author Ugurcan Orcun --- @version 0.5 +-- @version 0.6 -- @changelog --- Added focused Track/Take name display --- Added basic styling --- Settings now saved between sessions --- Refresh button fixed --- Added cursor automove option --- Minor layout changes +-- Updated styling +-- Changed CC pane layout +-- Added Velocity/Pitch focus buttons -- @link Forum Thread https://forum.cockos.com/showthread.php?t=288344 -- @about -- A small MIDI Editor tool for auto-inserting KeySwitch midi notes and managing note/cc names. @@ -25,14 +22,17 @@ ActivatedArticulations = {} EnumThemeColors = { - -- Curiosity_Killed by Miaka on ColourLovers - E = 0x99173Cff, - D = 0x2E2633ff, - C = 0x555152ff, - B = 0xDCE9BEff, - A = 0xEFFFCDff + A = 0x0c1017ff, -- Background + B = 0x212226FF, -- Default + C = 0xa4adceFF, -- Active + D = 0x636672FF, -- Hovered + E = 0xa7a8abff, -- HeaderText + F = 0xFFFFFFFF -- Text } +FontTitle = reaper.ImGui_CreateFont('sans-serif', 24, reaper.ImGui_FontFlags_Italic()) +Font = reaper.ImGui_CreateFont('sans-serif', 14) + ActiveTakeName = nil ActiveTrackName = nil ActiveTrackColor = 0xFFFFFFFF @@ -40,6 +40,7 @@ ActiveTrackColor = 0xFFFFFFFF Setting_AutoupdateTextEvent = true Setting_MoveEditCursor = true Setting_MaxColumns = 2 +Setting_FontSizeMultiplier = 1 Modal_Settings = false @@ -49,6 +50,7 @@ function SaveSettings() reaper.SetExtState("ReaKS", "Setting_AutoupdateTextEvent", tostring(Setting_AutoupdateTextEvent), true) reaper.SetExtState("ReaKS", "Setting_MaxColumns", tostring(Setting_MaxColumns), true) reaper.SetExtState("ReaKS", "Setting_MoveEditCursor", tostring(Setting_MoveEditCursor), true) + reaper.SetExtState("ReaKS", "Setting_FontSizeMultiplier", tostring(Setting_MoveEditCursor), true) end function LoadSettings() @@ -61,6 +63,9 @@ function LoadSettings() val = reaper.GetExtState("ReaKS", "Setting_MoveEditCursor") if val ~= "" then Setting_MoveEditCursor = val == "true" end + + val = reaper.GetExtState("ReaKS", "Setting_FontSizeMultiplier") + if val ~= "" then Setting_FontSizeMultiplier = tonumber(val) end end function UpdateActiveTargets() @@ -72,22 +77,18 @@ function UpdateActiveTargets() Articulations = {} CC = {} RefreshGUI() - end - - PreviousTake = ActiveTake - if ActiveTake ~= nil then ActiveTakeName = reaper.GetTakeName(ActiveTake) _, ActiveTrackName = reaper.GetTrackName(ActiveTrack) - else - ActiveTakeName = "No Take Selected" + + ActiveTrackColor = reaper.GetTrackColor(ActiveTrack) + if ActiveTrackColor == 0 then ActiveTrackColor = 0xFFFFFFFF end + + local r, g, b = reaper.ColorFromNative(ActiveTrackColor) + ActiveTrackColor = reaper.ImGui_ColorConvertDouble4ToU32(r/255, g/255, b/255, 1) end - ---[[ ActiveTrackColor = reaper.GetTrackColor(ActiveTrack) - if ActiveTrackColor == 0 then ActiveTrackColor = 0xFFFFFFFF - else - ActiveTrackColor = reaper.ImGui_ColorConvertNative(ActiveTrackColor) - end ]] + + PreviousTake = ActiveTake end function UpdateTextEvents() @@ -226,33 +227,41 @@ function RefreshGUI() end function StylingStart(ctx) - reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_WindowBg(), EnumThemeColors.D) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_WindowBg(), EnumThemeColors.A) - reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Button(), EnumThemeColors.C) - reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_ButtonActive(), EnumThemeColors.B) - reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_ButtonHovered(), EnumThemeColors.E) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Button(), EnumThemeColors.B) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_ButtonActive(), EnumThemeColors.C) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_ButtonHovered(), EnumThemeColors.D) - reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_FrameBg(), EnumThemeColors.C) - reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_FrameBgActive(), EnumThemeColors.B) - reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_FrameBgHovered(), EnumThemeColors.A) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_FrameBg(), EnumThemeColors.B) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_FrameBgActive(), EnumThemeColors.C) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_FrameBgHovered(), EnumThemeColors.D) + + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Text(), EnumThemeColors.F) + + reaper.ImGui_PushFont(ctx, Font) end function StylingEnd(ctx) - reaper.ImGui_PopStyleColor(ctx, 7) + reaper.ImGui_PopStyleColor(ctx, 8) + reaper.ImGui_PopFont(ctx) end -- UI Part local ctx = reaper.ImGui_CreateContext('ReaKS') +reaper.ImGui_Attach(ctx, Font) +reaper.ImGui_Attach(ctx, FontTitle) + local function loop() + StylingStart(ctx) + local visible, open = reaper.ImGui_Begin(ctx, 'ReaKS', true) if visible then - - --StylingStart(ctx) - + if (ActiveTakeName ~= nil and ActiveTrackName ~= nil) then - --[[ reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Text(), ActiveTrackColor) ]] - reaper.ImGui_Text(ctx, ActiveTrackName .. " - " .. ActiveTakeName) - --[[ reaper.ImGui_PopStyleColor(ctx, 1) ]] + reaper.ImGui_PushFont(ctx, FontTitle) + reaper.ImGui_TextColored(ctx, ActiveTrackColor, ActiveTrackName .. " - " .. ActiveTakeName) + reaper.ImGui_PopFont(ctx) end reaper.ImGui_BeginGroup(ctx) @@ -291,13 +300,12 @@ local function loop() SaveSettings() end - if reaper.ImGui_Button(ctx, "Rename Last Clicked CC Lane") then RenameAliasCCLane() end if reaper.ImGui_Button(ctx, "Find More Note Names >>>") then reaper.CF_ShellExecute("https://stash.reaper.fm/tag/Key-Maps") end reaper.ImGui_EndGroup(ctx) end - if ActiveTake == nil and Articulations ~= nil then + if ActiveTake == nil then reaper.ImGui_Separator(ctx) reaper.ImGui_Text(ctx, "No active MIDI take is open in the MIDI editor.") else @@ -318,16 +326,28 @@ local function loop() reaper.ImGui_EndTable(ctx) end - if ActiveTake ~= nil and CC ~= nil then - reaper.ImGui_SeparatorText(ctx, "Focus CC Lane") + if ActiveTake ~= nil then + reaper.ImGui_SeparatorText(ctx, "Focus to CC Lane") for i = 128, 255 do if CC[i] ~= nil then - if reaper.ImGui_Button(ctx, CC[i] .. " (CC" .. i - 128 .. ")") then FocusToCCLane(i-128) end + reaper.ImGui_Text(ctx, CC[i] .. " (CC" .. i - 128 .. ")" ) + reaper.ImGui_SameLine(ctx, reaper.ImGui_GetWindowWidth(ctx) - (reaper.ImGui_CalcTextSize(ctx, "Focus") * 2)) + if reaper.ImGui_Button(ctx, "Focus##"..i) then FocusToCCLane(i-128) end end end + + reaper.ImGui_Text(ctx, "Velocity") + reaper.ImGui_SameLine(ctx, reaper.ImGui_GetWindowWidth(ctx) - (reaper.ImGui_CalcTextSize(ctx, "Focus") * 2)) + if reaper.ImGui_Button(ctx, "Focus##velocity") then FocusToCCLane(512) end + + reaper.ImGui_Text(ctx, "Pitch") + reaper.ImGui_SameLine(ctx, reaper.ImGui_GetWindowWidth(ctx) - (reaper.ImGui_CalcTextSize(ctx, "Focus") * 2)) + if reaper.ImGui_Button(ctx, "Focus##pitch") then FocusToCCLane(513) end + + if reaper.ImGui_Button(ctx, "Rename Last Clicked CC Lane...") then RenameAliasCCLane() end end ---StylingEnd(ctx) + StylingEnd(ctx) reaper.ImGui_End(ctx) end From c27da2d6f8f7e6c693f477fcddb4f57bfc4492fc Mon Sep 17 00:00:00 2001 From: Kabraxist Date: Sat, 2 Mar 2024 16:43:12 +0300 Subject: [PATCH 5/5] ReaKS 0.7 Update --- MIDI Editor/ugurcanorcun_ReaKS.lua | 76 +++++++++++++++++------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/MIDI Editor/ugurcanorcun_ReaKS.lua b/MIDI Editor/ugurcanorcun_ReaKS.lua index f81c8d5ed..8264aa893 100644 --- a/MIDI Editor/ugurcanorcun_ReaKS.lua +++ b/MIDI Editor/ugurcanorcun_ReaKS.lua @@ -1,10 +1,10 @@ -- @description ReaKS - Keyswitch Articulation Manager -- @author Ugurcan Orcun --- @version 0.6 +-- @version 0.7 -- @changelog --- Updated styling --- Changed CC pane layout --- Added Velocity/Pitch focus buttons +-- Switched to Collapsing Headers +-- Automove for Playhead Position Insert +-- Styling Mismatch Fix -- @link Forum Thread https://forum.cockos.com/showthread.php?t=288344 -- @about -- A small MIDI Editor tool for auto-inserting KeySwitch midi notes and managing note/cc names. @@ -20,7 +20,6 @@ Articulations = {} CC = {} ActivatedArticulations = {} - EnumThemeColors = { A = 0x0c1017ff, -- Background B = 0x212226FF, -- Default @@ -189,6 +188,10 @@ function ToggleNote(noteNumber) local playheadPosition = reaper.MIDI_GetPPQPosFromProjTime(ActiveTake, playheadPosition) local length = playheadPosition + (reaper.MIDI_GetGrid(ActiveTake) * PPQ) reaper.MIDI_InsertNote(ActiveTake, false, false, playheadPosition - 1, length, 0, noteNumber, 100, false) + + if Setting_MoveEditCursor then + reaper.SetEditCurPos(reaper.MIDI_GetProjTimeFromPPQPos(ActiveTake, length), Setting_MoveEditCursor, false) + end else --Add articulation to selected notes reaper.MIDI_InsertNote(ActiveTake, false, false, earliestStartTime - 1, latestEndTime, 0, noteNumber, 100, false) @@ -239,11 +242,17 @@ function StylingStart(ctx) reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Text(), EnumThemeColors.F) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Header(), EnumThemeColors.B) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_HeaderActive(), EnumThemeColors.C) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_HeaderHovered(), EnumThemeColors.D) + + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_CheckMark(), EnumThemeColors.F) + reaper.ImGui_PushFont(ctx, Font) end function StylingEnd(ctx) - reaper.ImGui_PopStyleColor(ctx, 8) + reaper.ImGui_PopStyleColor(ctx, 12) reaper.ImGui_PopFont(ctx) end @@ -253,10 +262,10 @@ reaper.ImGui_Attach(ctx, Font) reaper.ImGui_Attach(ctx, FontTitle) local function loop() - StylingStart(ctx) local visible, open = reaper.ImGui_Begin(ctx, 'ReaKS', true) if visible then + StylingStart(ctx) if (ActiveTakeName ~= nil and ActiveTrackName ~= nil) then reaper.ImGui_PushFont(ctx, FontTitle) @@ -309,42 +318,43 @@ local function loop() reaper.ImGui_Separator(ctx) reaper.ImGui_Text(ctx, "No active MIDI take is open in the MIDI editor.") else - reaper.ImGui_SeparatorText(ctx, "Articulations") - - --TODO Make the table upside down - reaper.ImGui_BeginTable(ctx, "Articulations", Setting_MaxColumns) - - for i = 0, 127 do - if Articulations[i] ~= nil then - reaper.ImGui_TableNextColumn(ctx) - local articulation = Articulations[i] - if reaper.ImGui_Checkbox(ctx, articulation, ActivatedArticulations[i] ~= nil) then - ToggleNote(i) + if reaper.ImGui_CollapsingHeader(ctx, "Articulations", false) then + --TODO Make the table upside down + reaper.ImGui_BeginTable(ctx, "Articulations", Setting_MaxColumns) + + for i = 0, 127 do + if Articulations[i] ~= nil then + reaper.ImGui_TableNextColumn(ctx) + local articulation = Articulations[i] + if reaper.ImGui_Checkbox(ctx, articulation, ActivatedArticulations[i] ~= nil) then + ToggleNote(i) + end end end + reaper.ImGui_EndTable(ctx) end - reaper.ImGui_EndTable(ctx) end if ActiveTake ~= nil then - reaper.ImGui_SeparatorText(ctx, "Focus to CC Lane") - for i = 128, 255 do - if CC[i] ~= nil then - reaper.ImGui_Text(ctx, CC[i] .. " (CC" .. i - 128 .. ")" ) - reaper.ImGui_SameLine(ctx, reaper.ImGui_GetWindowWidth(ctx) - (reaper.ImGui_CalcTextSize(ctx, "Focus") * 2)) - if reaper.ImGui_Button(ctx, "Focus##"..i) then FocusToCCLane(i-128) end + if reaper.ImGui_CollapsingHeader(ctx, "CC Lanes", false) then + for i = 128, 255 do + if CC[i] ~= nil then + reaper.ImGui_Text(ctx, CC[i] .. " (CC" .. i - 128 .. ")" ) + reaper.ImGui_SameLine(ctx, reaper.ImGui_GetWindowWidth(ctx) - (reaper.ImGui_CalcTextSize(ctx, "Focus") * 2)) + if reaper.ImGui_Button(ctx, "Focus##"..i) then FocusToCCLane(i-128) end + end end - end - reaper.ImGui_Text(ctx, "Velocity") - reaper.ImGui_SameLine(ctx, reaper.ImGui_GetWindowWidth(ctx) - (reaper.ImGui_CalcTextSize(ctx, "Focus") * 2)) - if reaper.ImGui_Button(ctx, "Focus##velocity") then FocusToCCLane(512) end + reaper.ImGui_Text(ctx, "Velocity") + reaper.ImGui_SameLine(ctx, reaper.ImGui_GetWindowWidth(ctx) - (reaper.ImGui_CalcTextSize(ctx, "Focus") * 2)) + if reaper.ImGui_Button(ctx, "Focus##velocity") then FocusToCCLane(512) end - reaper.ImGui_Text(ctx, "Pitch") - reaper.ImGui_SameLine(ctx, reaper.ImGui_GetWindowWidth(ctx) - (reaper.ImGui_CalcTextSize(ctx, "Focus") * 2)) - if reaper.ImGui_Button(ctx, "Focus##pitch") then FocusToCCLane(513) end + reaper.ImGui_Text(ctx, "Pitch") + reaper.ImGui_SameLine(ctx, reaper.ImGui_GetWindowWidth(ctx) - (reaper.ImGui_CalcTextSize(ctx, "Focus") * 2)) + if reaper.ImGui_Button(ctx, "Focus##pitch") then FocusToCCLane(513) end - if reaper.ImGui_Button(ctx, "Rename Last Clicked CC Lane...") then RenameAliasCCLane() end + if reaper.ImGui_Button(ctx, "Rename Last Clicked CC Lane...") then RenameAliasCCLane() end + end end StylingEnd(ctx)