Commit 524791b4 authored by simon's avatar simon
Browse files

notes and octaves

parent c57f4ebc
Loading
Loading
Loading
Loading
+18 −9
Original line number Diff line number Diff line
@@ -15,21 +15,29 @@ func main() {
	events := Capture(
		Channel{10, HID.OnLong},  // event[0] button #10 long pressed
		Channel{1, HID.OnClose},  // event[1] button #1 closes
		Channel{1, HID.OnRotate}, // event[2] hat #1 rotates
		Channel{2, HID.OnRotate}, // event[2] hat #2 rotates
		Channel{7, HID.OnOpen},  // event[1] button #1 closes
		Channel{8, HID.OnOpen},  // event[1] button #1 closes
		Channel{2, HID.OnRotate}, // event[2] hat #1 rotates
		Channel{1, HID.OnRotate}, // event[2] hat #2 rotates
	)
	var x float32 = .5
	var f time.Duration = time.Second / 440
	var volume float32 = .5
	var octave =5
	var note int =1
	for {
		select {
		case <-events[0]:
			return
		case <-events[1]:
			play(NewSound(NewTone(f, float64(x)), time.Second/3))
		case h := <-events[2]:
			x = h.(HatAngleEvent).Angle/6.28 + .5
		case h := <-events[3]:
			f = time.Duration(100*math.Pow(2, float64(h.(HatAngleEvent).Angle)/6.28)) * time.Second / 44000
			play(NewSound(NewTone(Period(octave,note), float64(volume)), time.Second/3))
		case <-events[2]:
			octave++
		case <-events[3]:
			octave--
		case h := <-events[4]:
			volume = h.(HatAngleEvent).Angle/6.28 + .5
		case h := <-events[5]:
			//f = time.Duration(100*math.Pow(2, float64(h.(HatAngleEvent).Angle)/6.28)) * time.Second / 44000
			note = int(h.(HatAngleEvent).Angle*6 / math.Pi)
		}
	}
}
@@ -50,3 +58,4 @@ func play(s Sound) {