// connect timidity to port, send a ready signal once connected.
connect timidity to port, send a ready signal once connected.
// connect timidity to port send a ready signal once connected .
func connectTimitidy(port string, ready chan struct{}, done <-chan bool, err chan<- error) {
	n := 0
	for {
		out, e := exec.Command("aconnect", "-l").CombinedOutput()
		if e != nil {
			if n > 4 {
				err <- errors.New(string(out))
				return
			}
			n++
			time.Sleep(500 * time.Millisecond)
			continue
		}
		end := bytes.LastIndex(out, []byte(": 'TiMidity'"))
		if end < 0 {
			if n > 4 {
				err <- errors.New("No TiMitidy alsa port found")
				return
			}
			n++
			time.Sleep(time.Second)
			continue
		}
		start := bytes.LastIndexByte(out[:end], ' ')
		tport := string(out[start+1 : end])
		out, e = exec.Command("aconnect", port, tport).CombinedOutput()
		if e != nil {
			if n > 4 {
				err <- errors.New(string(out))
				return
			}
			n++
			time.Sleep(500 * time.Millisecond)
			continue
		}
		Debug.Printf("Signaling timidity is connected")
		signalOnce(ready)
		return
	}
}
func connectTimitidy ( port string , ready chan struct { } , done <- chan bool , err chan <- error ) { n := 0 for { out , e := exec . Command ( " " , " " ) . CombinedOutput ( ) if e != nil { if n > 4 { err <- errors . New ( string ( out ) ) return } n ++ time . Sleep ( 500 * time . Millisecond ) continue } end := bytes . LastIndex ( out , [ ] byte ( " " ) ) if end < 0 { if n > 4 { err <- errors . New ( " " ) return } n ++ time . Sleep ( time . Second ) continue } start := bytes . LastIndexByte ( out [ : end ] , ' ' ) tport := string ( out [ start + 1 : end ] ) out , e = exec . Command ( " " , port , tport ) . CombinedOutput ( ) if e != nil { if n > 4 { err <- errors . New ( string ( out ) ) return } n ++ time . Sleep ( 500 * time . Millisecond ) continue } Debug . Printf ( " " ) signalOnce ( ready ) return } }
connect timidity to port, send a ready signal once connected.
connect timidity to port send a ready signal once connected .
// get alsa ports // get timidity port // connect timitity to main port // we only signal it once, if timidity fails and restarts, aplaymidi is already reading music