asynchronous - MIDI beat clock in Java -
i'm creating drum machine , i'm having problems outputting midi beat clock. simplicity, i've set internal clock run calling thread.sleep(_time), _time amount of time sixteenth note calculated following code:
/** * calculates length of semiquaver in sequencer * @return time of semiquaver in milliseconds */ private void calculatetempo() { log.i(debug_tag , "calculated tempo."); /** * fjÀrdedelsnot */ _quarternote = 60000/_tempo; /** * sextondel */ _sixteenthnote = (_quarternote/4); } _tempo integer value bpm. said, drum machine runs fine, when outputting beat clock i'm running problems. beat clock in slaved device expects recieve 24 pulses per quarter note, gives rate of 6 pulses per sixteenth note. i'm using timer.scheduleatfixedrate adding messages output queue.
say have tempo of 120 bpm, gives time of 60000/120 = 500 per quarter note, 125 milli seconds every sixteenth note. every sixteenth note should have 6 pulses, 125 / 6 = 20.83333.. can see why puts me in bit of pickle. scheduleatfixedrate takes milli seconds parameter, must make counter higher precision, if use nanoseconds things start drift after while..
i've been combing through java midi api trying find that'll me in can't seem find methods designed this. if have suggestions please tell.
cheers. /m
according this link can use object.wait(millis, nanos) , thread.sleep(millis, nanos) available java 5. if want schedule threads suggests using scheduledthreadpoolexecutor.
i have found this library, maybe worth check.
good luck!
Comments
Post a Comment