From 4259388dec7eeb806c82a891b496c82b74327fa2 Mon Sep 17 00:00:00 2001 From: Aurora Date: Wed, 18 Aug 2021 22:37:18 +0300 Subject: [PATCH] Implement the new set of playback shortcuts fix step mode step mode now allows vertical movement even when playing --- src/api/playback API.ts | 4 ++- .../audio/system/src/playback manager.ts | 22 +++++++----- src/scripts/audio/system/src/script.ts | 5 ++- src/settings/shortcuts.json5 | 8 +++-- src/system/ipc/editor.ts | 4 +-- src/ui/elements/playbuttonsbar/main.ts | 8 ++--- src/ui/misc/tab.ts | 3 +- src/ui/windows/editor.ts | 34 ++++++++++++++++--- 8 files changed, 62 insertions(+), 26 deletions(-) diff --git a/src/api/playback API.ts b/src/api/playback API.ts index 857d33c..49fb86b 100644 --- a/src/api/playback API.ts +++ b/src/api/playback API.ts @@ -54,9 +54,11 @@ export class PlaybackAPI { public fetchRow(): null|PatternCellData[] { // check step mode if(this.stepMode) { - if(this.steps-- === 0) { + if(this.steps === 0) { return null; } + + --this.steps; } // fetch the row diff --git a/src/scripts/audio/system/src/playback manager.ts b/src/scripts/audio/system/src/playback manager.ts index b1c8958..0a21d0d 100644 --- a/src/scripts/audio/system/src/playback manager.ts +++ b/src/scripts/audio/system/src/playback manager.ts @@ -108,10 +108,9 @@ export class PlaybackManager implements PlaybackManagerAPI { } this.repeat = repeat; - this.step = step; - this.api.stepMode = step; - if(step) { + // handle step mode initialization + if((this.step = this.api.stepMode = step)) { this.api.steps++; } else { @@ -123,8 +122,10 @@ export class PlaybackManager implements PlaybackManagerAPI { * Helper function to load the next row data and keep the UI up to date */ public loadDataRow(): PatternCellData[]|null { - // send the current row to ui - this.messageFunc(false, ipcEnum.ManagerPosition, this.row + (this.pattern * this.patternLen), () => 0); + if(!this.step) { + // send the current row to ui + this.messageFunc(false, ipcEnum.ManagerPosition, this.row + (this.pattern * this.patternLen), () => 0); + } // load the current row data into ret variable const ret:PatternCellData[] = []; @@ -148,6 +149,11 @@ export class PlaybackManager implements PlaybackManagerAPI { } } + if(this.step) { + // send the next row to ui + this.messageFunc(false, ipcEnum.ManagerPosition, this.row + (this.pattern * this.patternLen), () => 0); + } + // return the previous row return ret; } @@ -156,10 +162,8 @@ export class PlaybackManager implements PlaybackManagerAPI { * Inform the UI the playback has stopped */ public stop(): void { - if(!this.step) { - // send the current row to ui - this.messageFunc(false, ipcEnum.ManagerPosition, -1, () => 0); - } + // send the current row to ui + this.messageFunc(false, ipcEnum.ManagerPosition, -1, () => 0); } /** diff --git a/src/scripts/audio/system/src/script.ts b/src/scripts/audio/system/src/script.ts index 798dfb7..b8f2e60 100644 --- a/src/scripts/audio/system/src/script.ts +++ b/src/scripts/audio/system/src/script.ts @@ -244,7 +244,10 @@ parentPort?.on("message", (data:{ token?:number, code:string, data:unknown, fn?: playManager.setMode(arr.row, arr.repeat, arr.step); // tell the driver to start playback - driver.reset(); + if(!arr.step) { + driver.reset(); + } + driver.play(); } diff --git a/src/settings/shortcuts.json5 b/src/settings/shortcuts.json5 index 9045f2d..f729bbf 100644 --- a/src/settings/shortcuts.json5 +++ b/src/settings/shortcuts.json5 @@ -157,9 +157,11 @@ "ui.save": [ "ctrl+S" ], /* shortcut for saving the project */ "ui.saveas": [ "ctrl+shift+S" ], /* shortcut for saving the project as another file */ - "ui.play": [ "Enter" ], /* shortcut for playing back the entire track */ - "ui.playpattern": [ "Shift+Enter" ], /* shortcut for playing back the current pattern */ - "ui.stop": [ "Shift+Enter", "Enter" ], /* shortcut for stopping playback */ + "ui.play": [ "Enter", "F5" ], /* shortcut for playing from start */ + "ui.playpattern": [ "F6" ], /* shortcut for playing back the current pattern */ + "ui.playrow": [ "F7" ], /* shortcut for playing from the current row */ + "ui.playstep": [ "ctrl+Enter" ], /* shortcut for playing from the current row */ + "ui.stop": [ "F5", "F6", "F7", "Enter" ], /* shortcut for stopping playback */ "ui.record": [ "Space" ], /* shortcut for toggling record mode */ "ui.muteselected": [ "F9" ], /* shortcut for muting selected channel */ diff --git a/src/system/ipc/editor.ts b/src/system/ipc/editor.ts index 8cda069..c141c97 100644 --- a/src/system/ipc/editor.ts +++ b/src/system/ipc/editor.ts @@ -121,9 +121,9 @@ ipcMain.on(ipcEnum.DriverInit, (event, token, channels) => { }); }); -ipcMain.on(ipcEnum.DriverPlay, (event, token, row, repeat) => { +ipcMain.on(ipcEnum.DriverPlay, (event, token, row, repeat, step) => { // post the info - workerAsync("module-play", { row, repeat, }, undefined, () => { + workerAsync("module-play", { row, repeat, step, }, undefined, () => { // tell the UI we finished event.reply(ipcEnum.DriverPlay, token); }); diff --git a/src/ui/elements/playbuttonsbar/main.ts b/src/ui/elements/playbuttonsbar/main.ts index 5977c0e..e6e76ec 100644 --- a/src/ui/elements/playbuttonsbar/main.ts +++ b/src/ui/elements/playbuttonsbar/main.ts @@ -98,9 +98,7 @@ export class PlayBar implements UIComponent { click: async(e:MouseEvent) => { // change playback mode to play all if(e.button === 0 && Tab.active && Tab.active.playMode !== PlayMode.PlayAll) { - const row = Tab.active?.activeRow ?? 0; - - if(await startPlayback(row - (row % (Tab.active?.module?.patternRows ?? 1)), false, false)) { + if(await startPlayback(0, false, false)) { Tab.active.playMode = PlayMode.PlayAll; } } @@ -114,9 +112,9 @@ export class PlayBar implements UIComponent { click: async(e:MouseEvent) => { // change playback mode to play pattern if(e.button === 0 && Tab.active && Tab.active.playMode !== PlayMode.PlayPattern) { - const row = Tab.active?.activeRow ?? 0; + const row = Tab.active.activeRow; - if(await startPlayback(row - (row % (Tab.active?.module?.patternRows ?? 1)), true, false)) { + if(await startPlayback(row - (row % (Tab.active.module?.patternRows ?? 1)), true, false)) { Tab.active.playMode = PlayMode.PlayPattern; } } diff --git a/src/ui/misc/tab.ts b/src/ui/misc/tab.ts index c511ad3..143d5dd 100644 --- a/src/ui/misc/tab.ts +++ b/src/ui/misc/tab.ts @@ -91,7 +91,7 @@ export class Tab { * Whether to block vertical movement in the pattern editor and matrix editor */ public get blockMovement(): boolean { - return this.follow && this._playMode !== PlayMode.Stopped; + return this.follow && this._playMode !== PlayMode.Stopped && this._playMode !== PlayMode.PlayStep; } /** @@ -304,4 +304,5 @@ export enum PlayMode { Stopped = 0, // not playing anything right now PlayAll = 1, // playing the entire song in repeat (including loop point) PlayPattern = 2, // playing the current pattern + PlayStep = -1, // playing step by step with user input } diff --git a/src/ui/windows/editor.ts b/src/ui/windows/editor.ts index 61b6abf..eff7e07 100644 --- a/src/ui/windows/editor.ts +++ b/src/ui/windows/editor.ts @@ -351,9 +351,21 @@ async function loadMainShortcuts() { } // toggle play mode - const row = Tab.active?.activeRow ?? 0; + if(await startPlayback(0, false, false)){ + Tab.active.playMode = PlayMode.PlayAll; + } + + return true; + }, - if(await startPlayback(row - (row % (Tab.active?.module?.patternRows ?? 1)), false, false)){ + /* shortcut for enabling play mode */ + playrow: async() => { + if(!Tab.active || Tab.active.playMode === PlayMode.PlayAll){ + return false; + } + + // toggle play mode + if(await startPlayback(Tab.active.playMode === PlayMode.Stopped ? Tab.active.activeRow : -1, false, false)){ Tab.active.playMode = PlayMode.PlayAll; } @@ -367,15 +379,29 @@ async function loadMainShortcuts() { } // toggle play mode - const row = Tab.active?.activeRow ?? 0; + const row = Tab.active.activeRow; - if(await startPlayback(row - (row % (Tab.active?.module?.patternRows ?? 1)), true, false)){ + if(await startPlayback(row - (row % (Tab.active.module?.patternRows ?? 1)), true, false)){ Tab.active.playMode = PlayMode.PlayPattern; } return true; }, + /* shortcut for enabling play mode */ + playstep: async() => { + if(!Tab.active){ + return false; + } + + // toggle play mode + if(await startPlayback(Tab.active.activeRow, false, true)){ + Tab.active.playMode = PlayMode.PlayStep; + } + + return true; + }, + /* shortcut for disabling playback mode */ // eslint-disable-next-line require-await stop: () => {