func Main(score *audio.Score, band audio.Band) { _, path, _, _ := runtime.Caller(1) name := filepath.Base(path) name = name[:len(name)-3] path = filepath.Dir(path) if len(os.Args) > 1 { switch os.Args[1] { case "edit": procs := runtime.GOMAXPROCS(0) if procs < 2 { procs = 2 } runtime.GOMAXPROCS(procs) gui.Run(func() { gui.NewWindow(nil, name, func(w *gui.Window) { v := NewScoreView(score, band) v.path = filepath.Join(path, "score.go") w.SetCentralView(v) v.InitFocus() }) }) case "write": Write(audio.NewScorePlayer(score, band), filepath.Join(path, name+".wav")) default: println("unknown arg: " + os.Args[1]) } } else { audio.Play(audio.NewScorePlayer(score, band)) } }
func NewScoreView(score *audio.Score, band audio.Band) *ScoreView { s := &ScoreView{score: score, band: band, scaleTime: 32} s.ViewBase = NewView(s) instruments := audio.BandInstruments(band) loop: for name := range instruments { for _, part := range score.Parts { if part.Name == name { continue loop } } score.Parts = append(score.Parts, &audio.Part{Name: name}) fmt.Println("added part for instrument " + name) } // TODO: warn about parts without instruments for _, part := range score.Parts { p := newPartView(s, part) s.parts = append(s.parts, p) s.Add(p) } s.timeGrid = &uniformGrid{0, 1} s.player = audio.NewScorePlayer(score, band) s.play = make(chan bool, 1) s.close = make(chan bool) go s.animate() return s }