Commit graph

11 commits

Author SHA1 Message Date
Peter Elliott
b82f2df4c8 Piano: Add UI support for different lengths of notes 2020-10-12 19:41:53 +02:00
Peter Elliott
01bff0141e Piano: Highlight pressed key in roll widget 2020-10-12 19:41:53 +02:00
Brian Gianforcaro
e160181a73 Piano: Uninitialized member variables in RollWidet, found by Coverity
This seem like they wouldn't cause any problems in reality,
but it's nice to fix them to avoid any future misuse.
2020-08-17 09:17:57 +02:00
William McPherson
ee52572ca1 Piano: Allow multiple tracks internally
This commit adds multi-track functionality without exposing it to the
user.

All I really did was rename AudioEngine to Track and allow more than one
Track in TrackManager. A lot of the changes are just changing widgets to
take a TrackManager and use current_track().

The TrackManager creates Tracks and gives them a read-only reference to
the global time value. When the TrackManager wants to fill a sample in
the buffer (in fill_buffer()), it calls fill_sample() on each Track.

The delay code is slightly different - a Track will fill its
m_delay_buffer with the sample it just created rather than the most
recent sample in the buffer (which used to be the same thing).

TrackManager manages the current octave.

Other than those few things, this is a pretty basic separation of
concerns.
2020-06-18 16:42:37 +02:00
William McPherson
72cbbd5297 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.
2020-02-27 10:21:13 +01:00
Andreas Kling
3d20da9ee4 Userspace: Use Core::Object::add() when building interfaces 2020-02-23 11:10:52 +01:00
Andreas Kling
6a9cc66b97 LibGUI: Remove leading G from filenames 2020-02-06 20:33:02 +01:00
William McPherson
9a05bbaace Piano: Move piano roll internals to AudioEngine
The piano roll data definitely belongs in AudioEngine along with the
note and time data. Now RollWidget only has GUI information, much like
the other widgets.

Note that this commit exacerbates issue #1158 which is caused by
RollWidget::paint_event().
2020-02-06 19:13:53 +01:00
joshua stein
c3a32108b2 Piano: Fix building with clang 2020-02-05 18:39:45 +01:00
Andreas Kling
c5bd9d4ed1 LibGUI: Put all classes in the GUI namespace and remove the leading G
This took me a moment. Welcome to the new world of GUI::Widget! :^)
2020-02-02 15:15:33 +01:00
William McPherson
4a36a51618 Piano: Rewrite application
Goals:
- Switch to a more typical LibGUI arrangement
- Separate GUI (MainWidget) and audio (AudioEngine)
- Improve on existing features while retaining the same feature set

Improvements:
- Each GUI element is a separate widget
- The wave (WaveWidget) scales with the window
- The piano roll (RollWidget) scales horizontally and scrolls vertically
- The piano (KeysWidget) fits as many notes as possible
- The knobs (KnobsWidget) are now sliders
- All mouse and key events are handled in constant time
- The octave can be changed while playing notes
- The same note can be played with the mouse, keyboard and roll at the
  same time, and the volume of the resulting note is scaled accordingly
- Note frequency constants use the maximum precision available in a
  double
2020-01-31 13:13:04 +01:00