generated from thinkode/modelRepository
34-midi (#35)
Closes #34 Implement MIDI peripherals Implement device concept Cleaning project Reviewed-on: #35
This commit was merged in pull request #35.
This commit is contained in:
37
project.go
37
project.go
@@ -77,7 +77,7 @@ func (a *App) CreateProject() error {
|
||||
Avatar: "appicon.png",
|
||||
Comments: "Write your comments here",
|
||||
},
|
||||
make(map[string]hardware.PeripheralInfo),
|
||||
make(map[string]hardware.EndpointInfo),
|
||||
}
|
||||
|
||||
// The project isn't saved for now
|
||||
@@ -127,16 +127,12 @@ func (a *App) OpenProject(projectInfo ProjectInfo) error {
|
||||
// Send an event with the project data
|
||||
runtime.EventsEmit(a.ctx, "LOAD_PROJECT", projectInfo.ShowInfo)
|
||||
|
||||
// Load all peripherals of the project
|
||||
projectPeripherals := a.projectInfo.PeripheralsInfo
|
||||
for key, value := range projectPeripherals {
|
||||
hostFinder, err := a.hardwareManager.GetFinder(value.ProtocolName)
|
||||
// Load all endpoints of the project
|
||||
projectEndpoints := a.projectInfo.EndpointsInfo
|
||||
for key, value := range projectEndpoints {
|
||||
_, err = a.hardwareManager.RegisterEndpoint(a.ctx, value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to find the finder '%s': %w", value.ProtocolName, err)
|
||||
}
|
||||
_, err = hostFinder.RegisterPeripheral(a.ctx, value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to register the peripheral S/N '%s': %w", key, err)
|
||||
return fmt.Errorf("unable to register the endpoint S/N '%s': %w", key, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -144,16 +140,12 @@ func (a *App) OpenProject(projectInfo ProjectInfo) error {
|
||||
|
||||
// CloseCurrentProject closes the current project
|
||||
func (a *App) CloseCurrentProject() error {
|
||||
// Unregistrer all peripherals of the project
|
||||
projectPeripherals := a.projectInfo.PeripheralsInfo
|
||||
for key, value := range projectPeripherals {
|
||||
hostFinder, err := a.hardwareManager.GetFinder(value.ProtocolName)
|
||||
// Unregister all endpoints of the project
|
||||
projectEndpoints := a.hardwareManager.SavedEndpoints
|
||||
for key, value := range projectEndpoints {
|
||||
err := a.hardwareManager.UnregisterEndpoint(a.ctx, value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to find the finder '%s': %w", value.ProtocolName, err)
|
||||
}
|
||||
err = hostFinder.UnregisterPeripheral(a.ctx, value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to unregister the peripheral S/N '%s': %w", key, err)
|
||||
return fmt.Errorf("unable to unregister the endpoint S/N '%s': %w", key, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,6 +196,9 @@ func (a *App) SaveProject() (string, error) {
|
||||
a.projectSave = fmt.Sprintf("%04d%02d%02d%02d%02d%02d%s", date.Year(), date.Month(), date.Day(), date.Hour(), date.Minute(), date.Second(), projectExtension)
|
||||
log.Debug().Str("file", "project").Str("newProjectSave", a.projectSave).Msg("projectSave is null, getting a new one")
|
||||
}
|
||||
// Get hardware info
|
||||
a.projectInfo.EndpointsInfo = a.hardwareManager.SavedEndpoints
|
||||
// Marshal the project
|
||||
data, err := yaml.Marshal(a.projectInfo)
|
||||
if err != nil {
|
||||
log.Err(err).Str("file", "project").Any("projectInfo", a.projectInfo).Msg("unable to format the project information")
|
||||
@@ -243,6 +238,6 @@ type ProjectMetaData struct {
|
||||
|
||||
// ProjectInfo defines all the information for a lighting project
|
||||
type ProjectInfo struct {
|
||||
ShowInfo ShowInfo `yaml:"show"` // Show information
|
||||
PeripheralsInfo map[string]hardware.PeripheralInfo `yaml:"peripherals"` // Peripherals information
|
||||
ShowInfo ShowInfo `yaml:"show"` // Show information
|
||||
EndpointsInfo map[string]hardware.EndpointInfo `yaml:"endpoints"` // Endpoints information
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user