From 10bf0c6a061f5f095e686beb29c1752c2f5202b4 Mon Sep 17 00:00:00 2001 From: HiveBeats Date: Sat, 17 Jun 2023 16:03:07 +0400 Subject: [PATCH] feat: detect note pressed --- main.c | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 23408c0..7008030 100644 --- a/main.c +++ b/main.c @@ -376,23 +376,63 @@ void pack(uint16_t* d, size_t length) { write_file("output.wav", buffer, fileSize); } +size_t detect_note_pressed(Note* note) { + size_t is_pressed = 0; + note->length = 1; + if (IsKeyPressed(KEY_A)) { + strcpy(note->name, "A4"); + is_pressed = 1; + } + if (IsKeyPressed(KEY_B)) { + strcpy(note->name, "B4"); + is_pressed = 1; + } + if (IsKeyPressed(KEY_C)) { + strcpy(note->name, "C4"); + is_pressed = 1; + } + if (IsKeyPressed(KEY_D)) { + strcpy(note->name, "D4"); + is_pressed = 1; + } + if (IsKeyPressed(KEY_E)) { + strcpy(note->name, "E4"); + is_pressed = 1; + } + if (IsKeyPressed(KEY_F)) { + strcpy(note->name, "F4"); + is_pressed = 1; + } + if (IsKeyPressed(KEY_G)) { + strcpy(note->name, "G4"); + is_pressed = 1; + } + return is_pressed; +} + //------------------------------------------------------------------------------------ // Main //------------------------------------------------------------------------------------ int main(int argc, char **argv) { - const size_t width = 1280; - const size_t height = 720; + const size_t width = 640; + const size_t height = 480; InitWindow(width, height, "SeeSynth - v0.1"); - //SetTargetFPS(60); - + SetTargetFPS(60); + Note current_note = { + .length = 1, + .name = malloc(sizeof(char) * 3) + }; // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here + if (detect_note_pressed(¤t_note)) { + SynthSound sound = get_note_sound(current_note); + printf("Note played: %s\n", current_note.name); + } //---------------------------------------------------------------------------------- // Draw