MIDI device start of implementation

This commit is contained in:
2025-11-16 21:44:48 +01:00
parent 19ec0bec74
commit 76b705012c
4 changed files with 43 additions and 12 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
build/bin
projects
mapping
node_modules
frontend/.vscode
frontend/dist

View File

@@ -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")
}

View File

@@ -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

View File

@@ -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