grimmdude / MidiWriterJS

♬ A JavaScript library which provides an API for programmatically generating and creating expressive multi-track MIDI files and JSON.
MIT License
547 stars 58 forks source link

How to caculate "tick" properly? #87

Closed humbleCoder1990 closed 2 years ago

humbleCoder1990 commented 2 years ago

스크린샷 2022-01-19 오전 2 00 21

I tried to make 1 bar with 16 notes.

So, I caculated durationTick like this.

const duration = 1920 / 16 /* 1920 ticks are 1 bar */

then,

const startTick = duration * noteIndex

But the result is almost 4 bars like the screenshot. What are I missing something? How to caculate ticks properly?

MidiWriterJS uses another value for meaning 1 bar of ticks?

humbleCoder1990 commented 2 years ago

Wow I just saw another post https://github.com/grimmdude/MidiWriterJS/issues/58, 128 ticks for per beat. It's very confusing.

grimmdude commented 2 years ago

Hi @humbleCoder1990,

That's correct, there are 128 ticks per beat. That's how it's specified in MIDI 🤷‍♂️