func main() { flag.Parse() sequencer := NewSequencer() for _, file := range flag.Args() { pattern, err := drum.DecodeFile(file) if err != nil { log.Fatal(err) } if err := sequencer.Add(pattern); err != nil { log.Fatal(err) } log.Print(pattern.String()) } portaudio.Initialize() defer portaudio.Terminate() stream, err := portaudio.OpenDefaultStream(0, 2, 44100, 0, func(o []int32) { sequencer.Read(o) }) if err != nil { log.Fatal(err) } defer stream.Close() stream.Start() defer stream.Stop() sequencer.Start() for { time.Sleep(time.Second) } }
func main() { if len(os.Args) != 2 { fmt.Println("usage: tdrum file.splice") os.Exit(1) } pattern, err := drum.DecodeFile(os.Args[1]) if err != nil { fmt.Printf("error: %s\n", err) os.Exit(1) } sequencer = NewSequencer() if err := sequencer.Add(pattern); err != nil { fmt.Printf("error: %s\n", err) os.Exit(1) } portaudio.Initialize() defer portaudio.Terminate() stream, err := portaudio.OpenDefaultStream(0, 2, 44100, 0, func(o []int32) { sequencer.Read(o) }) if err != nil { log.Fatal(err) } defer stream.Close() stream.Start() defer stream.Stop() if err := termbox.Init(); err != nil { panic(err) } defer termbox.Close() termbox.SetOutputMode(termbox.Output256) eq := make(chan termbox.Event) go func() { for { eq <- termbox.PollEvent() } }() draw(pattern) loop: for { select { case ev := <-eq: if ev.Type == termbox.EventKey && ev.Key == termbox.KeyEsc { break loop } if ev.Type == termbox.EventKey && ev.Key == termbox.KeySpace { if sequencer.Running { sequencer.Reset() } else { sequencer.Start() } } default: draw(pattern) time.Sleep(time.Millisecond * 2) } } }