Esempio n. 1
0
func midiLoop(s *portmidi.Stream) {
	noteOn := make([]int64, 0, 128)
	for e := range s.Listen() {
		switch e.Status {
		case 144: // note on
			on := false
			for _, n := range noteOn {
				if n == e.Data1 {
					on = true
				}
			}
			if !on {
				noteOn = append(noteOn, e.Data1)
			}
			atomic.StoreInt64(&midiNote, e.Data1)
			atomic.StoreInt64(&midiGate, 1)
		case 128: // note off
			for i, n := range noteOn {
				if n == e.Data1 {
					copy(noteOn[i:], noteOn[i+1:])
					noteOn = noteOn[:len(noteOn)-1]
				}
			}
			if len(noteOn) > 0 {
				n := noteOn[len(noteOn)-1]
				atomic.StoreInt64(&midiNote, n)
			} else {
				atomic.StoreInt64(&midiGate, 0)
			}
		}
	}
}
Esempio n. 2
0
func midiLoop(s *portmidi.Stream) {
	var n int64
	for e := range s.Listen() {
		switch e.Status {
		case 144: // note on
			n = e.Data1
			atomic.StoreInt64(&midiNote, n)
			atomic.StoreInt64(&midiGate, 1)
		case 128: // note off
			if e.Data1 == n {
				atomic.StoreInt64(&midiGate, 0)
			}
		}
	}
}
Esempio n. 3
0
func AllNotesOff(stream *portmidi.Stream) {
	stream.WriteShort(0xB0|(midiChan-1), 0x7B, 0x00)
	playing = -1
}
Esempio n. 4
0
func NoteOff(stream *portmidi.Stream, note int64, velocity int64) {
	stream.WriteShort(0x80|(midiChan-1), note, velocity)
	playing = -1
}
Esempio n. 5
0
func NoteOn(stream *portmidi.Stream, note int64, velocity int64) {
	playing = note
	stream.WriteShort(0x90|(midiChan-1), note, velocity)
}