From 9643b407321e0b6b6d974e467cb357fbf9804338 Mon Sep 17 00:00:00 2001 From: Nils Tijtgat Date: Fri, 22 Sep 2023 10:33:44 +0200 Subject: [PATCH] Amai Zeg Wauw setup --- src/app/app.component.html | 6 +++ src/app/app.component.ts | 108 +++++++++++++++++++++++++++++-------- 2 files changed, 92 insertions(+), 22 deletions(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index ba18e4d..3bb1cf1 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -30,3 +30,9 @@ 16 + + + + + + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index defdf71..bad64b5 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -20,6 +20,20 @@ export class AppComponent { outputDeviceControl = new FormControl(); midiChannelControl = new FormControl(1); + noteMidiOutputDevice: WebMidi.MIDIOutput | null = null; + + midiNoteMap: Record = { + 0: 0, + 1: 1, + 2: 2, + 3: 3, + 4: 55, + 5: 51, + 6: 6, + 7: 7, + 8: 8, + }; + constructor() { navigator.requestMIDIAccess().then((access) => { const midiOutputDevices = Array.from(access.outputs.values()); @@ -28,6 +42,15 @@ export class AppComponent { this.midiOutputDevices = midiOutputDevices; this.midiOutputDevice = midiOutputDevices[1]; this.outputDeviceControl.setValue(this.midiOutputDevice); + + console.log(midiOutputDevices); + + for (const device of midiOutputDevices) { + if (device.name === 'Swissonic MidiConnect 2 Port 1') { + this.noteMidiOutputDevice = device; + console.log(device); + } + } } }); } @@ -72,35 +95,76 @@ export class AppComponent { await device.claimInterface(0); while (true) { - const result = await device.transferIn(1, 128); - - if (result.data && this.midiOutputDevice && this.midiChannelControl.value) { - if (result.data.byteLength === 8) { - const buttonBits = result.data.getInt8(1); - - // Update switch values - for (let i = 0; i < 8; i++) { - if (this.isBitEnabled(this.lastButtonBits, i) !== this.isBitEnabled(buttonBits, i)) { - if (Boolean(buttonBits >> i)) { - this.midiOutputDevice.send([144 + this.midiChannelControl.value - 1, i, 127]); - } else { - this.midiOutputDevice.send([144 + this.midiChannelControl.value - 1, i, 0]); + try { + const result = await device.transferIn(1, 128); + if (result.data && this.midiOutputDevice && this.midiChannelControl.value) { + if (result.data.byteLength === 8) { + const buttonBits = result.data.getInt8(1); + + console.log('DATA BINNEN'); + + // Update switch values + for (let i = 0; i < 8; i++) { + if (this.isBitEnabled(this.lastButtonBits, i) !== this.isBitEnabled(buttonBits, i)) { + const outValue = Boolean(buttonBits >> i) ? 127 : 0; + + switch (i) { + case 0: + this.midiOutputDevice.send([144 + 2, 54, outValue]); + break; + case 1: + this.midiOutputDevice.send([144 + 2, 50, outValue]); + break; + case 2: + this.midiOutputDevice.send([144 + 2, 56, outValue]); + break; + case 3: + this.midiOutputDevice.send([144 + 2, 57, outValue]); + break; + case 4: + this.midiOutputDevice.send([144 + 2, 55, outValue]); + break; + case 5: + this.midiOutputDevice.send([144 + 2, 51, outValue]); + this.midiOutputDevice.send([144 + 15, 1, outValue]); + break; + } } } + this.lastButtonBits = buttonBits; } - this.lastButtonBits = buttonBits; - } - // Update expression pedal value - if (result.data.byteLength === 33) { - const expressionPedalValue = result.data.getInt16(5); - const mappedExpressionPedalValue = this.convertExpressionPedalValue(expressionPedalValue); - if (mappedExpressionPedalValue !== this.lastExpressionPedalValue) { - this.midiOutputDevice.send([176 + this.midiChannelControl.value - 1, 1, mappedExpressionPedalValue]); - this.lastExpressionPedalValue = mappedExpressionPedalValue; + // Update expression pedal value + if (result.data.byteLength === 33) { + const expressionPedalValue = result.data.getInt16(5); + const mappedExpressionPedalValue = this.convertExpressionPedalValue(expressionPedalValue); + if (mappedExpressionPedalValue !== this.lastExpressionPedalValue) { + this.midiOutputDevice.send([176 + this.midiChannelControl.value - 1, 1, mappedExpressionPedalValue]); + this.lastExpressionPedalValue = mappedExpressionPedalValue; + } } } + } catch (error) { + console.log(error); } } } + + startTune(tune: number) { + if (this.noteMidiOutputDevice) { + this.noteMidiOutputDevice.send([144 + 4, tune, 127]); + this.noteMidiOutputDevice.send([144 + 4, tune, 0]); + } + } + + stopTune() { + console.log(this.noteMidiOutputDevice); + + if (this.noteMidiOutputDevice) { + console.log('jo'); + + this.noteMidiOutputDevice.send([144 + 4, 11, 127]); + this.noteMidiOutputDevice.send([144 + 11, 10, 0]); + } + } }