diff --git a/.gitignore b/.gitignore index 8195664..25e933e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ build/bin projects +mapping node_modules frontend/.vscode frontend/dist diff --git a/hardware/MIDIFinder.go b/hardware/MIDIFinder.go index 62b46af..d062ef2 100644 --- a/hardware/MIDIFinder.go +++ b/hardware/MIDIFinder.go @@ -242,18 +242,19 @@ func (f *MIDIFinder) scanPeripherals(ctx context.Context) error { } baseName := normalizeName(port.String()) + sn := strings.ReplaceAll(strings.ToLower(baseName), " ", "_") - if _, ok := currentMap[baseName]; !ok { - currentMap[baseName] = &MIDIPeripheral{ + if _, ok := currentMap[sn]; !ok { + currentMap[sn] = &MIDIPeripheral{ info: PeripheralInfo{ Name: baseName, - SerialNumber: baseName, + SerialNumber: sn, ProtocolName: "MIDI", }, } } - currentMap[baseName].inputPorts = append(currentMap[baseName].inputPorts, port) + currentMap[sn].inputPorts = append(currentMap[sn].inputPorts, port) log.Info().Any("peripherals", currentMap).Msg("available MIDI IN ports") } @@ -270,17 +271,19 @@ func (f *MIDIFinder) scanPeripherals(ctx context.Context) error { } baseName := normalizeName(port.String()) - if _, ok := currentMap[baseName]; !ok { - currentMap[baseName] = &MIDIPeripheral{ + sn := strings.ReplaceAll(strings.ToLower(baseName), " ", "_") + + if _, ok := currentMap[sn]; !ok { + currentMap[sn] = &MIDIPeripheral{ info: PeripheralInfo{ Name: baseName, - SerialNumber: baseName, + SerialNumber: sn, ProtocolName: "MIDI", }, } } - currentMap[baseName].outputsPorts = append(currentMap[baseName].outputsPorts, port) + currentMap[sn].outputsPorts = append(currentMap[sn].outputsPorts, port) log.Info().Any("peripherals", currentMap).Msg("available MIDI OUT ports") } diff --git a/hardware/MIDIPeripheral.go b/hardware/MIDIPeripheral.go index b54a564..09d8243 100644 --- a/hardware/MIDIPeripheral.go +++ b/hardware/MIDIPeripheral.go @@ -10,15 +10,24 @@ import ( "gitlab.com/gomidi/midi" ) +// MIDIDevice represents the device to control +type MIDIDevice struct { + ID string // Device ID + Mapping MappingInfo // Device mapping configuration +} + +// ------------------- // + // MIDIPeripheral contains the data of a MIDI peripheral type MIDIPeripheral struct { wg sync.WaitGroup inputPorts []midi.In outputsPorts []midi.Out + info PeripheralInfo // The peripheral info + settings map[string]interface{} // The settings of the peripheral - info PeripheralInfo // The peripheral info - settings map[string]interface{} // The settings of the peripheral + devices []MIDIDevice // All the MIDI devices that the peripheral can handle } // NewMIDIPeripheral creates a new MIDI peripheral diff --git a/hardware/interfaces.go b/hardware/interfaces.go index 6c9ea82..dc8308d 100644 --- a/hardware/interfaces.go +++ b/hardware/interfaces.go @@ -2,6 +2,21 @@ package hardware import "context" +// MappingInfo is the configuration for each device +type MappingInfo struct { + DeviceInfo struct { + Name string `yaml:"name"` + Manufacturer string `yaml:"manufacturer"` + Type string `yaml:"type"` + } `yaml:"device"` + Features map[string]any `yaml:"features"` +} + +// Device represents the methods used to manage a device (logic element include in a Peripheral) +type Device interface { + Configure() error // Load the mapping for the device +} + // Peripheral represents the methods used to manage a peripheral (input or output hardware) type Peripheral interface { Connect(context.Context) error // Connect the peripheral @@ -9,12 +24,15 @@ type Peripheral interface { Disconnect(context.Context) error // Disconnect the peripheral Activate(context.Context) error // Activate the peripheral Deactivate(context.Context) error // Deactivate the peripheral + AddDevice(Device) error // Add a device to the peripheral + RemoveDevice(Device) error // Remove a device to the peripheral + GetSettings() map[string]any // Get the peripheral settings SetSettings(context.Context, map[string]any) error // Set a peripheral setting SetDeviceProperty(context.Context, uint32, byte) error // Update a device property WaitStop() error // Properly close the peripheral - GetInfo() PeripheralInfo // Get the peripheral information - GetSettings() map[string]any // Get the peripheral settings + GetInfo() PeripheralInfo // Get the peripheral information + } // PeripheralInfo represents a peripheral information