Пример #1
0
//Run this as a go routine to handle asynchronous output
//cache requests.
func (cache OutputCache) outputCacheHandler() {
	_cache := make(map[string]map[int]gocmc.Output)

	for true {
		select {
		case req := <-cache.requestChannel:
			//have we cached _anything_ for this output yet?
			if outputs, outputCached := _cache[req.outputName]; outputCached {
				if output, exists := outputs[req.midiChannel]; exists {
					req.replyChannel <- output
				} else {
					fmt.Printf("New channel for %s\n", req.outputName)
					destination := gocmc.GetDestinations()[req.outputName].Endpoint
					output := cache.client.NewOutput(req.outputName+"-output", req.midiChannel, destination)
					outputs[req.midiChannel] = output
					_cache[req.outputName] = outputs
					req.replyChannel <- output
				}
			} else {
				fmt.Println("No existing output, creating")
				destination := gocmc.GetDestinations()[req.outputName].Endpoint
				output := cache.client.NewOutput(req.outputName+"-output", req.midiChannel, destination)
				fmt.Println("New output: ", output)
				outputs := make(map[int]gocmc.Output)
				outputs[req.midiChannel] = output
				_cache[req.outputName] = outputs
				req.replyChannel <- output
			}
		}
	}
}
Пример #2
0
func main() {
	bpm := flag.Int("bpm", 60, "beats per minute")
	ppqn := flag.Int("ppqn", 24, "pulses per quarter note, default is 24 and that's probably what you want")
	cycle := flag.Int("cycle", 24, "number of quarter notes before the cycle count resets, can affect sequence start/stop times")
	host := flag.String("host", "localhost", "address to listen for HTTP")
	port := flag.String("port", "4000", "port for HTTP requests")
	flag.Parse()

	stepLen := 60000 / *bpm / *ppqn
	pulsesPerCycle := *ppqn * *cycle
	listenAddress := *host + ":" + *port

	fmt.Printf("bpm:  %d\nppqn:  %d\ncycle length:  %d\n", *bpm, *ppqn, *cycle)
	fmt.Printf("pulse length (ms):  %d\npulse count per cycle:  %d\n", stepLen, pulsesPerCycle)
	fmt.Printf("listening for HTTP at:  %s\n", listenAddress)

	destinations := gocmc.GetDestinations()
	fmt.Println("Destinations: ", destinations)

	client := gocmc.MakeClient("goseq")

	fmt.Println("Starting controller and handler")
	con := NewController(pulsesPerCycle, stepLen)
	StartSequenceHandler(con, client)

	StartDestinationsHandler()
	StartControlHandler(con)

	fmt.Println("Starting server")
	http.ListenAndServe(listenAddress, nil)
}
Пример #3
0
func (du DestinationUpdates) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	destinations := gocmc.GetDestinations()

	w.Write(destinationsToJson(destinations))
}