feat: added recording MIDI device feature.
This commit is contained in:
@@ -79,6 +79,7 @@ interface AppConfig {
|
||||
enable_audio_capture_for_screen_sharing: boolean;
|
||||
lookahead_time: number;
|
||||
playback_delay: number;
|
||||
recording_offset: number;
|
||||
};
|
||||
templates: {
|
||||
custom_instructions: string;
|
||||
@@ -250,7 +251,8 @@ export class ConfigManager {
|
||||
audio: {
|
||||
enable_audio_capture_for_screen_sharing: false,
|
||||
lookahead_time: 0.05,
|
||||
playback_delay: 0.2
|
||||
playback_delay: 0.2,
|
||||
recording_offset: 0
|
||||
},
|
||||
templates: {
|
||||
custom_instructions: ''
|
||||
|
||||
@@ -15,6 +15,10 @@ export class KGMidiInput {
|
||||
private isInitialized: boolean = false;
|
||||
private connectedInputs: Map<string, MIDIInput> = new Map();
|
||||
|
||||
// Recording callbacks
|
||||
private onRecordNoteOn: ((pitch: number) => void) | null = null;
|
||||
private onRecordNoteOff: ((pitch: number) => void) | null = null;
|
||||
|
||||
// Private constructor to prevent direct instantiation
|
||||
private constructor() {
|
||||
console.log("KGMidiInput initialized");
|
||||
@@ -161,11 +165,13 @@ export class KGMidiInput {
|
||||
if (command === 0x90 && velocity > 0) {
|
||||
console.log(`MIDI Note On: pitch=${pitch}, velocity=${velocity}, channel=${channel}`);
|
||||
this.triggerNoteOn(pitch, velocity);
|
||||
this.onRecordNoteOn?.(pitch);
|
||||
}
|
||||
// Note Off: command = 0x80 (128) or Note On with velocity 0
|
||||
else if (command === 0x80 || (command === 0x90 && velocity === 0)) {
|
||||
console.log(`MIDI Note Off: pitch=${pitch}, channel=${channel}`);
|
||||
this.triggerNoteOff(pitch);
|
||||
this.onRecordNoteOff?.(pitch);
|
||||
}
|
||||
// Control Change: command = 0xB0 (176)
|
||||
else if (command === 0xb0) {
|
||||
@@ -264,6 +270,16 @@ export class KGMidiInput {
|
||||
}
|
||||
}
|
||||
|
||||
// ===== RECORDING =====
|
||||
|
||||
public setRecordingCallbacks(
|
||||
onNoteOn: ((pitch: number) => void) | null,
|
||||
onNoteOff: ((pitch: number) => void) | null
|
||||
): void {
|
||||
this.onRecordNoteOn = onNoteOn;
|
||||
this.onRecordNoteOff = onNoteOff;
|
||||
}
|
||||
|
||||
// ===== GETTERS =====
|
||||
|
||||
public getIsInitialized(): boolean {
|
||||
|
||||
Reference in New Issue
Block a user