Loading README.md +11 −9 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ Example: play a note when pressing button #1. (button #10 to exit) hat changes f "io" "os/exec" "time" "math" ) import . "github.com/splace/joysticks" Loading @@ -25,9 +26,9 @@ Example: play a note when pressing button #1. (button #10 to exit) hat changes f func main() { events := Capture( channel{10, state.OnOpen}, // event[0] button #10 opens channel{1, state.OnClose}, // event[1] button #1 closes channel{1, state.OnMove}, // event[2] hat #1 moves Channel{10, State.OnOpen}, // event[0] button #10 opens Channel{1, State.OnClose}, // event[1] button #1 closes Channel{1, State.OnMove}, // event[2] hat #1 moves ) var x float32 = .5 var f time.Duration = time.Second / 440 Loading @@ -38,8 +39,8 @@ Example: play a note when pressing button #1. (button #10 to exit) hat changes f case <-events[1]: play(NewSound(NewTone(f, float64(x)), time.Second/3)) case h := <-events[2]: x = h.(HatChangeEvent).x/2 + .5 f = time.Duration(100*math.Pow(2, float64(h.(HatChangeEvent).y))) * time.Second / 44000 x = h.(HatChangeEvent).X/2 + .5 f = time.Duration(100*math.Pow(2, float64(h.(HatChangeEvent).Y))) * time.Second / 44000 } } } Loading @@ -48,7 +49,7 @@ Example: play a note when pressing button #1. (button #10 to exit) hat changes f cmd := exec.Command("aplay") out, in := io.Pipe() go func() { Encode(in, s, 44100,2) Encode(in, 2, 44100, s) in.Close() }() cmd.Stdin = out Loading @@ -60,3 +61,4 @@ Example: play a note when pressing button #1. (button #10 to exit) hat changes f Loading
README.md +11 −9 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ Example: play a note when pressing button #1. (button #10 to exit) hat changes f "io" "os/exec" "time" "math" ) import . "github.com/splace/joysticks" Loading @@ -25,9 +26,9 @@ Example: play a note when pressing button #1. (button #10 to exit) hat changes f func main() { events := Capture( channel{10, state.OnOpen}, // event[0] button #10 opens channel{1, state.OnClose}, // event[1] button #1 closes channel{1, state.OnMove}, // event[2] hat #1 moves Channel{10, State.OnOpen}, // event[0] button #10 opens Channel{1, State.OnClose}, // event[1] button #1 closes Channel{1, State.OnMove}, // event[2] hat #1 moves ) var x float32 = .5 var f time.Duration = time.Second / 440 Loading @@ -38,8 +39,8 @@ Example: play a note when pressing button #1. (button #10 to exit) hat changes f case <-events[1]: play(NewSound(NewTone(f, float64(x)), time.Second/3)) case h := <-events[2]: x = h.(HatChangeEvent).x/2 + .5 f = time.Duration(100*math.Pow(2, float64(h.(HatChangeEvent).y))) * time.Second / 44000 x = h.(HatChangeEvent).X/2 + .5 f = time.Duration(100*math.Pow(2, float64(h.(HatChangeEvent).Y))) * time.Second / 44000 } } } Loading @@ -48,7 +49,7 @@ Example: play a note when pressing button #1. (button #10 to exit) hat changes f cmd := exec.Command("aplay") out, in := io.Pipe() go func() { Encode(in, s, 44100,2) Encode(in, 2, 44100, s) in.Close() }() cmd.Stdin = out Loading @@ -60,3 +61,4 @@ Example: play a note when pressing button #1. (button #10 to exit) hat changes f