Skip to content
Open
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
27 changes: 24 additions & 3 deletions data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,24 @@
"inputs": [
{
"name": "Teensy MIDI",
"controlButtons": {},
"controlButtons": {
"A1": {
"channel": 0,
"note": 99
},
"A2": {
"channel": 0,
"note": 101
},
"A3": {
"channel": 0,
"note": 6
},
"A4": {
"channel": 0,
"note": 41
}
},
"clock": false,
"sustainPedal": null,
"mainTrigger": {
Expand Down Expand Up @@ -231,9 +248,9 @@
}
},
{
"name": "microKEY2 Air KEYBOARD",
"name": "Vortex Wireless 2",
"keyboard": {
"channel": 0
"channel": 1
}
}
],
Expand All @@ -242,6 +259,10 @@
"name": "Juno USB Midi",
"alias": "Juno"
},
{
"name": "JUNO-60",
"alias": "Juno"
},
{
"name": "USB Midi ",
"alias": "Juno"
Expand Down
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"start": "ts-node -r tsconfig-paths/register --transpile-only src/index.ts",
"dev": "ts-node-dev -r tsconfig-paths/register --respawn --transpile-only --ignore-watch node_modules --no-notify src/index.ts",
"debug": "ts-node-dev -r tsconfig-paths/register --respawn --transpile-only --ignore-watch node_modules --no-notify --inspect=4321 src/index.ts",
"dev2": "nodemon dist/src/index.js --no-stdin",
"build": "tsc -p .",
"build:watch": "tsc -p . --watch",
Expand Down
5 changes: 4 additions & 1 deletion server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Config} from '@shared/types/config_types/config_types';
import {UserDataState} from '@shared/state/user_data_state';

import {CHORDS} from '@shared/constants/chord_constants';
import {jimmySet1, jimmySet2, michaelSet1} from '@shared/constants/progression_constants';
import {jimmySet1, jimmySet2, michaelSet1, whatGoesOn} from '@shared/constants/progression_constants';

import {EasyMidi} from '@shared/types/easy_midi_types';

Expand All @@ -22,6 +22,7 @@ const conf: Config = config;
const songs: number[][][][] = [
// set1,
// set2,
whatGoesOn,
jimmySet1,
jimmySet2,
michaelSet1,
Expand All @@ -46,6 +47,8 @@ const app = new App(fullEasyMidi, process.stdin, conf, userData);
(async () => {
exitHandler(app);

await app.midiService.setupMidi();

const server = await initServer(app);
server.listen(1337);

Expand Down
18 changes: 11 additions & 7 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {initWebsocketServer} from './websocket_server';
export default async function initServer(app: App): Promise<http.Server> {
const server = express();

const actions = getActionMap(app);

server.use(express.json());
server.use(cors({
origin: [
Expand Down Expand Up @@ -50,18 +48,24 @@ export default async function initServer(app: App): Promise<http.Server> {
});

server.post<undefined, SubmitControlPanelActionAPIResponse, SerializedAction>('/action', async (req, res) => {
const action = req.body.action;
const actionName = req.body.action;

const actionButtons = app.progressionMode.getActions();

if (!actions[action]) {
res.json({error: 'No action found for ' + action});
const actionObj = actionButtons.find((button) => button.label === actionName);

if (!actionObj) {
res.json({error: 'No action found for ' + actionName});
return;
}

const actionFuncName = actionObj.label;

try {
await Promise.resolve(actions[action]());
await Promise.resolve(actionObj.action());
} catch (e: unknown) {
const e2 = e as Error;
console.error(`Error running action ${action}: ` + e2.message);
console.error(`Error running action ${actionFuncName}: ` + e2.message);

res.json({
error: e2.message,
Expand Down
66 changes: 8 additions & 58 deletions shared/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {EasyMidi} from './types/easy_midi_types';

import {GlobalState} from './state/global_state';
import {UserDataState} from './state/user_data_state';
import {AdhocProgressionState, ProgressionState} from './state/progression_state';
import {ProgressionState} from './state/progression_state';

import {ApplicationModeManager} from './application_mode_managers/application_mode_manager';
import AdhocChordCompositionMode from './application_mode_managers/adhoc_chord_mode/achoc_chord_composition_mode';
Expand All @@ -38,13 +38,14 @@ export default class App {
private config: Config,
private userData: UserDataState,
) {
this.progressionMode = new ProgressionModeManager(this.midiService, this.wledService, this.config, this);

this.globalStateSubject = new BehaviorSubject(this.getState());
this.controlButtonSubscription = this.midiService.subscribeToControlButtons(this.handleControlButton);

// this.adhocPlaybackMode = new AdhocChordPlaybackMode(initialState, this.midiService, this);
// this.activeMode = this.adhocPlaybackMode!;

this.progressionMode = new ProgressionModeManager(this.midiService, this.wledService, this.config, this);
this.activeMode = this.progressionMode;
}

Expand All @@ -63,7 +64,7 @@ export default class App {
midiService = new MidiService(this.midi, this.config);
wledService = new WledService(this.config);

progressionMode?: ProgressionModeManager;
progressionMode: ProgressionModeManager;
// progressionMode = new ProgressionModeManager(this.midiService, this.wledService, this.config, this);

chordSupervisor = new OutputChordSupervisor(this.midiService);
Expand All @@ -88,18 +89,7 @@ export default class App {
this.broadcastState();
};

getProgressionState: () => ProgressionState | undefined = () => this.progressionMode?.getState();
getAdhocState: () => AdhocProgressionState | undefined = () => {
if (this.adhocCompositionMode) {
this.adhocCompositionMode.getState();
}

if (this.adhocPlaybackMode) {
return this.adhocPlaybackMode.getState();
}

return undefined;
};
getProgressionState: () => ProgressionState = () => this.progressionMode.getState();

getState = (): GlobalState => {
const currentMode = this.activeMode && (this.activeMode as {constructor: {name: string}}).constructor.name as ApplicationModeName;
Expand All @@ -108,8 +98,9 @@ export default class App {
currentMode,
config: this.config,
userData: this.userData,
// progression: this.getProgressionState(),
adhocState: this.getAdhocState(),
progression: this.getProgressionState(),
actionButtons: this.progressionMode.getActions(),
// adhocState: this.getAdhocState(),
};
};

Expand All @@ -122,35 +113,6 @@ export default class App {
return this.globalStateSubject.subscribe(callback);
};

changeModeAdhocPlayback = (state: AdhocProgressionState) => {
if (this.adhocPlaybackMode) {
return;
}

this.adhocCompositionMode?.close();
this.adhocCompositionMode = undefined;

const newState: AdhocProgressionState = {...state, mode: 'playback'};
this.adhocPlaybackMode = new AdhocChordPlaybackMode(newState, this.midiService, this);
this.activeMode = this.adhocPlaybackMode;

this.broadcastState();
};

changeModeAdhocComposition = () => {
this.adhocPlaybackMode?.close();
this.adhocPlaybackMode = undefined;
this.adhocCompositionMode?.close();
this.adhocCompositionMode = undefined;

this.midiService.notesOffAll();

this.adhocCompositionMode = new AdhocChordCompositionMode(this.midiService, this);
this.activeMode = this.adhocCompositionMode;

this.broadcastState();
};

actions = {
toggleDrumsColorAction: () => this.progressionMode?.toggleDrumColorAction(),
toggleDrumsMusicAction: () => this.progressionMode?.toggleDrumMusicAction(),
Expand Down Expand Up @@ -180,18 +142,6 @@ export default class App {
nextPreset: () => {
this.wledService.setRandomPreset();
},

lockInProgression: () => {
if (!this.adhocCompositionMode) {
return;
}

const state = this.adhocCompositionMode.getState();
this.changeModeAdhocPlayback(state);
},
resetProgression: () => {
this.changeModeAdhocComposition();
},
};

playSpecificChord = (chord: number[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class AdhocChordPlaybackMode implements ApplicationModeManager<Ad
state.currentIndex = this.state.chords.length - 1;
const lastChord = this.state.chords[state.currentIndex];
if (lastChord) {
const notes = lastChord.map((n) => n.note);
const _notes = lastChord.map((n) => n.note);
// this.app.playSpecificChord(notes);
}
}
Expand Down
3 changes: 3 additions & 0 deletions shared/application_mode_managers/application_mode_manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {ActionFuncWithDescriptor} from '../types/action_button_types';

export interface ApplicationModeManager<T> {
getState(): T;
getActions(): ActionFuncWithDescriptor[];
close(): void;
}
Loading