mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:48:14 +00:00
Piano: New timing system and zoomable piano roll
This patch allows roll notes to be of different sizes. This necessitates a new internal representation of time. BPM and time signatures are mostly implemented but not exposed. Roll notes are now sample-accurate and the grid is aligned to 60 BPM 4/4. The roll is divided by the time signature raised to some power of 2, giving the musical divisions of (in the case of 4/4) 16, 32, 64 etc. Before, our timing was derived from the buffer size and we relied on that to implement delay. Delay has been rewritten to be sample-granular. It's now exposed as the proper "divisions of a beat". Something to be wary of is that the last buffer in the loop is also used for the start of the next loop. In other words, we loop mid-buffer. This means we write WAVs with a tiny bit of silence due to breaking the loop after filling half a buffer. The data structure for the roll is an array of SinglyLinkedLists of RollNotes. Separating by pitch (via the array layout) makes insertion much simpler and faster. Using sorted lists (and thus SinglyLinkedListIterators) to do lookups is very quick as you know the sample of the next note and can just compare it to the current sample. I implemented this with HashMaps and the cost of lookups was abysmal. I also tried a single SinglyLinkedList and the insertion code got even more complicated than it already is.
This commit is contained in:
parent
b1ed57e84b
commit
72cbbd5297
8 changed files with 215 additions and 91 deletions
|
@ -80,11 +80,13 @@ int main(int argc, char** argv)
|
|||
if (need_to_write_wav) {
|
||||
need_to_write_wav = false;
|
||||
audio_engine.reset();
|
||||
while (audio_engine.current_column() < horizontal_notes - 1) {
|
||||
audio_engine.set_should_loop(false);
|
||||
do {
|
||||
audio_engine.fill_buffer(buffer);
|
||||
wav_writer.write_samples(reinterpret_cast<u8*>(buffer.data()), buffer_size);
|
||||
}
|
||||
} while (audio_engine.time());
|
||||
audio_engine.reset();
|
||||
audio_engine.set_should_loop(true);
|
||||
wav_writer.finalize();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue