mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
Piano: Start working on a desktop piano.
The idea here is to implement a simple synhesizer that allows you to play music with your keyboard. :^) It's a huge hack currently but we can improve upon this.
This commit is contained in:
parent
f712ead1fb
commit
c962c54610
7 changed files with 531 additions and 0 deletions
35
Applications/Piano/main.cpp
Normal file
35
Applications/Piano/main.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "Music.h"
|
||||
#include "PianoWidget.h"
|
||||
#include <LibCore/CFile.h>
|
||||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GEventLoop.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
CFile audio("/dev/audio");
|
||||
if (!audio.open(CIODevice::WriteOnly)) {
|
||||
dbgprintf("Can't open audio device: %s", audio.error_string());
|
||||
return 1;
|
||||
}
|
||||
|
||||
GApplication app(argc, argv);
|
||||
|
||||
auto* window = new GWindow;
|
||||
window->set_title("Piano");
|
||||
window->set_rect(100, 100, 512, 512);
|
||||
|
||||
auto* piano_widget = new PianoWidget;
|
||||
window->set_main_widget(piano_widget);
|
||||
|
||||
window->show();
|
||||
|
||||
for (;;) {
|
||||
GEventLoop::current().pump(GEventLoop::WaitMode::PollForEvents);
|
||||
u8 buffer[4096];
|
||||
piano_widget->fill_audio_buffer(buffer, sizeof(buffer));
|
||||
audio.write(buffer, sizeof(buffer));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue