Skip to content

Commit

Permalink
Implement the new set of playback shortcuts
Browse files Browse the repository at this point in the history
fix step mode
step mode now allows vertical movement even when playing
  • Loading branch information
Awuwunya committed Aug 18, 2021
1 parent 1843ca4 commit 4259388
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 26 deletions.
4 changes: 3 additions & 1 deletion src/api/playback API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions src/scripts/audio/system/src/playback manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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[] = [];
Expand All @@ -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;
}
Expand All @@ -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);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/scripts/audio/system/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
8 changes: 5 additions & 3 deletions src/settings/shortcuts.json5
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions src/system/ipc/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
8 changes: 3 additions & 5 deletions src/ui/elements/playbuttonsbar/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ export class PlayBar implements UIComponent<HTMLDivElement> {
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;
}
}
Expand All @@ -114,9 +112,9 @@ export class PlayBar implements UIComponent<HTMLDivElement> {
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;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/ui/misc/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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
}
34 changes: 30 additions & 4 deletions src/ui/windows/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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: () => {
Expand Down

0 comments on commit 4259388

Please sign in to comment.