Example #1
0
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
}
Example #2
0
func (s *ScoreView) animate() {
	var next <-chan time.Time
	var ctrl audio.PlayControl
	for {
		select {
		case <-s.play:
			if next != nil {
				next = nil
				ctrl.Stop()
				break
			}
			for _, inst := range audio.BandInstruments(s.band) {
				inst.Stop()
			}
			ctrl = audio.PlayAsync(s.player)
			next = time.After(time.Second / 60)
		case <-next:
			next = time.After(time.Second / 60)
			Do(s, func() {
				s.cursorTime = s.player.GetTime()
				Repaint(s)
			})
		case <-ctrl.Done:
			next = nil
			Do(s, func() {
				SetKeyFocus(s.oldFocus)
			})
		case <-s.close:
			return
		}
	}
}
Example #3
0
func (s *ScoreView) editPattern(e *patternEventView) {
	p := NewPatternView(e.event.Pattern, audio.BandInstruments(s.band)[e.part.part.Name])
	p.closed = func() {
		s.pattern = nil
		s.reform()
		SetKeyFocus(e)
	}
	s.pattern = p
	s.Add(p)
	s.reform()
	p.InitFocus()
}