From 7cafe05118bccad1d468c9b1a283995253ba3f77 Mon Sep 17 00:00:00 2001 From: Mikhail Kot Date: Wed, 24 Jul 2024 00:44:53 +0100 Subject: [PATCH] Fix regression in #70 (#72) Fix regression in #70 Fix wording in readme Add midi sequence test Allow testing a single rks file --- README.md | 3 +- internal/gui/feedback/controller.lua | 1 + internal/state_machine/state_machine.lua | 17 ++- tests/compare | 2 +- tests/ignored_keys | 13 ++ tests/midi-sequence.RPP | 165 +++++++++++++++++++++++ tests/midi-sequence.rks | 14 ++ tests/test | 21 +-- 8 files changed, 217 insertions(+), 19 deletions(-) create mode 100644 tests/ignored_keys create mode 100644 tests/midi-sequence.RPP create mode 100644 tests/midi-sequence.rks diff --git a/README.md b/README.md index ac93e601..a1e9a374 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ a # add fx # close fx window im # insert midi item so # open in midi editor -0 # get to item start +0 # jump to project start a # add note and select it 5p # paste 5 more notes (last one is selected) NN # select two more previous notes @@ -159,7 +159,6 @@ chmod +x prepare copy-configs test If you don't use X11 you can have a look at `.github/workflows/wf.yml` to see how x11 is emulated with Xvfb. -Use `./test -s` to skip first invocation which bypasses "Still evaluating" window. ### Writing tests diff --git a/internal/gui/feedback/controller.lua b/internal/gui/feedback/controller.lua index 7cfad3ce..e843e25c 100644 --- a/internal/gui/feedback/controller.lua +++ b/internal/gui/feedback/controller.lua @@ -104,6 +104,7 @@ function feedback.displayState(state) and string_util.format("(rec %s..)", state['macro_register']) or "" model.setKeys({ right_text = right_text, mode = state['mode'] }) + feedback.update() end function feedback.clear() diff --git a/internal/state_machine/state_machine.lua b/internal/state_machine/state_machine.lua index c67eca6b..a9c2b0a4 100644 --- a/internal/state_machine/state_machine.lua +++ b/internal/state_machine/state_machine.lua @@ -124,8 +124,9 @@ end local function input() local _, _, section_id, _, _, _, _, ctx = reaper.get_action_context() if ctx == "" then return end + local main_ctx = section_id == 0 ---@type KeyPress - local hotkey = { context = section_id == 0 and "main" or "midi", key = ctxToState(ctx) } + local hotkey = { context = main_ctx and "main" or "midi", key = ctxToState(ctx) } log.info("Input: " .. format.line(hotkey)) if config.show_feedback_window then feedback.clear() end @@ -138,15 +139,19 @@ local function input() if not config.show_feedback_window then return end feedback.displayState(new_state) - feedback.update() - -- This works only when window is docked, nothing we can do otherwise - local defocus_window = section_id == 0 - and actions.FocusTracks or actions.FocusMidiEditor + -- If window is floating, it's controlled by WM so we can't always defocus it + if not config.dock_feedback_window then return end + + local defocus_window = main_ctx and actions.FocusTracks or actions.FocusMidiEditor reaper.Main_OnCommand(reaper.NamedCommandLookup(defocus_window), 0) -- When we insert track with feedback window closed, it steals focus and track is not renamed - if hotkey.key:lower() == "o" then reaper.Main_OnCommand(actions.RenameTrack, 0) end + if not main_ctx or not new_state or new_state.key_sequence ~= "" then return end + if not hotkey.key:lower():match "o" then return end + local keys = new_state.last_command.action_keys + if #keys ~= 1 or not keys[1]:match "^EnterTrack" then return end + reaper.Main_OnCommand(actions.RenameTrack, 0) end return input diff --git a/tests/compare b/tests/compare index 0ed0b682..56f8367d 100755 --- a/tests/compare +++ b/tests/compare @@ -3,7 +3,7 @@ from pathlib import Path from sys import argv left_file, right_file = Path(argv[1]).read_text(), Path(argv[2]).read_text() out = 0 -ignored_keys = [" + RIPPLE 0 + GROUPOVERRIDE 0 0 0 + AUTOXFADE 1 + ENVATTACH 3 + POOLEDENVATTACH 0 + MIXERUIFLAGS 11 48 + ENVFADESZ10 40 + PEAKGAIN 1 + FEEDBACK 0 + PANLAW 1 + PROJOFFS 0 0 0 + MAXPROJLEN 0 0 + GRID 3199 8 1 8 1 0 0 0 + TIMEMODE 1 5 -1 30 0 0 -1 + VIDEO_CONFIG 0 0 256 + PANMODE 3 + PANLAWFLAGS 3 + CURSOR 0.75 + ZOOM 100 0 0 + VZOOMEX 6 0 + USE_REC_CFG 0 + RECMODE 1 + SMPTESYNC 0 30 100 40 1000 300 0 0 1 0 0 + LOOP 0 + LOOPGRAN 0 4 + RECORD_PATH "Media" "" + + + RENDER_FILE "" + RENDER_PATTERN "" + RENDER_FMT 0 2 0 + RENDER_1X 0 + RENDER_RANGE 1 0 0 18 1000 + RENDER_RESAMPLE 3 0 1 + RENDER_ADDTOPROJ 0 + RENDER_STEMS 0 + RENDER_DITHER 0 + TIMELOCKMODE 1 + TEMPOENVLOCKMODE 1 + ITEMMIX 1 + DEFPITCHMODE 589824 0 + TAKELANE 1 + SAMPLERATE 44100 0 0 + + LOCK 1 + + GLOBAL_AUTO -1 + TEMPO 120 4 4 + PLAYRATE 1 0 0.25 4 + SELECTION 0 0 + SELECTION2 0 0 + MASTERAUTOMODE 0 + MASTERTRACKHEIGHT 0 0 + MASTERPEAKCOL 16576 + MASTERMUTESOLO 0 + MASTERTRACKVIEW 0 0.6667 0.5 0.5 0 0 0 0 0 0 0 0 0 0 + MASTERHWOUT 0 0 1 0 0 0 0 -1 + MASTER_NCH 2 2 + MASTER_VOLUME 1 0 -1 -1 1 + MASTER_PANMODE 3 + MASTER_PANLAWFLAGS 3 + MASTER_FX 1 + MASTER_SEL 0 + + + + + > + > + +> diff --git a/tests/midi-sequence.rks b/tests/midi-sequence.rks new file mode 100644 index 00000000..24b3aaf8 --- /dev/null +++ b/tests/midi-sequence.rks @@ -0,0 +1,14 @@ +o +test +&Return +0 +l +im +b +&space +so +a +2l +k +a +Z diff --git a/tests/test b/tests/test index d731574f..0e816340 100755 --- a/tests/test +++ b/tests/test @@ -1,16 +1,21 @@ #!/bin/bash ret=0 -[ $# -eq 0 ] && timeout 6 ./reaper/reaper -new -nosplash &>/dev/null # still evaluating +if [ $# -eq 0 ]; then + timeout 6 ./reaper/reaper -new -nosplash &>/dev/null # still evaluating + tests="*.rks" +else + tests=$@ +fi -for test in *.rks; do +for test in $tests; do echo "Running $test" expected=${test%.rks}.RPP out=out.RPP - ./reaper/reaper -saveas $out -new -nosplash 1>stdout 2>stderr & + ./reaper/reaper -saveas $out -new -nosplash &>/dev/null & pid=$(echo $!) sleep 1 - xdotool search --onlyvisible --all reaper windowfocus + xdotool search --onlyvisible --all reaper windowfocus &>/dev/null while read cmd; do if [[ $cmd == "&"* ]]; then @@ -18,6 +23,7 @@ for test in *.rks; do else xdotool type "$cmd" fi + sleep .1 done <$test xdotool type " ps" @@ -27,13 +33,8 @@ for test in *.rks; do ./compare $expected $out diff_ret=$(echo $?) echo "Test exit code $diff_ret" - echo Stdout: - cat stdout - echo Stderr: - cat stderr - ret=$(( ret + diff_ret )) - rm $out stdout stderr + rm $out done exit $ret