-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (67 loc) · 2.22 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"flag"
"fmt"
"log"
"mxml2patt/config"
"mxml2patt/parser"
"mxml2patt/hydrogen"
)
func main() {
// Define command-line flags
inputFile := flag.String("input", "", "Path to the MusicXML input file (overrides config.yaml)")
outputFile := flag.String("output", "", "Path for the output .h2pattern file (overrides config.yaml)")
flag.Parse()
// Load configuration
cfg, err := config.LoadConfig("config.yaml")
if err != nil {
log.Fatalf("Failed to load config: %v", err)
}
fmt.Printf("Config loaded: %+v\n", cfg)
// Override config paths with flags if provided
if *inputFile != "" {
cfg.InputFile = *inputFile
}
if *outputFile != "" {
cfg.OutputFile = *outputFile
}
// Display help message if input file is not specified
if cfg.InputFile == "" {
fmt.Println("Usage: go run main.go [--input <input file>] [--output <output file>]")
fmt.Println("Flags:")
flag.PrintDefaults()
return
}
// Parse MusicXML file
notes, err := parser.ParseMusicXML(cfg.InputFile, cfg)
if err != nil {
log.Fatalf("Failed to parse MusicXML: %v", err)
}
fmt.Printf("Parsed notes: %+v\n", notes)
// Calculate maximum ticks for scaling positions
totalTicks := 0
for _, note := range notes {
if note.Position > totalTicks {
totalTicks = note.Position
}
}
// Define pattern length in ticks
patternLength := 384
// Create the Hydrogen pattern and distribute notes
pattern := hydrogen.NewHydrogenPattern(cfg.Tempo, patternLength)
for _, note := range notes {
if totalTicks > 0 {
scaledPosition := int(float64(note.Position) * float64(patternLength) / float64(totalTicks))
pattern.AddNoteAtPosition(note.Instrument, note, scaledPosition)
} else {
pattern.AddNoteAtPosition(note.Instrument, note, 0)
}
}
fmt.Printf("Generated Hydrogen pattern: %+v\n", pattern)
// Export pattern to file
err = pattern.ExportToFile(cfg.OutputFile)
if err != nil {
log.Fatalf("Failed to export pattern: %v", err)
}
fmt.Println("Pattern exported to", cfg.OutputFile)
}