Last active
September 8, 2017 23:11
-
-
Save IljaN/73da0920d40829eafd66b35b58469f58 to your computer and use it in GitHub Desktop.
Simple Midiclock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"time" | |
) | |
const target_bmp = 121.00 | |
const uspm = 6000000 | |
func main() { | |
midi_start := []byte{0xfa} | |
//midi_stop := []byte{0xfc} | |
midi_tick := []byte{0xf8} | |
//midi_continue := []byte{0xfb} | |
fmt.Println("Midi Clock test") | |
m, err := os.OpenFile("/dev/snd/midiC1D0", os.O_WRONLY, 0664) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println("Midi start") | |
m.Write(midi_start) | |
m.Sync() | |
pulse_interval := bpmToPulseInterval(target_bmp) | |
fmt.Printf("Calculated Interval:%v", pulse_interval) | |
for { | |
m.Write(midi_tick) | |
time.Sleep(pulse_interval * time.Microsecond) | |
} | |
} | |
func bpmToPulseInterval(bpm float64) time.Duration { | |
return time.Duration((uspm / (bpm / 10)) / 24) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment