示例#1
0
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))
	}
}
示例#2
0
文件: beep.go 项目: gordonklaus/songs
func main() {
	w := &window{voices: map[int]*sineVoice{}}
	p := audio.Params{SampleRate: 96000}
	audio.Init(w, p)

	portaudio.Initialize()
	defer portaudio.Terminate()
	s, err := portaudio.OpenDefaultStream(0, 1, p.SampleRate, 64, w.processAudio)
	if err != nil {
		fmt.Println(err)
		return
	}
	if err := s.Start(); err != nil {
		fmt.Println(err)
		return
	}
	defer s.Stop()

	if err := gui.Run(func() {
		gui.NewWindow(w, "beep", func(win *gui.Window) {
			w.Window = win
			gui.SetKeyFocus(w)
		})
	}); err != nil {
		fmt.Println(err)
	}
}