commit 290e9da2c1cf21a012e9af5b4b642f9ab0491ec0 Author: Federico Polidoro Date: Sat Sep 16 18:15:23 2023 -0300 Merge branch 'dev' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e256265 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# ignora la carpeta de compilados +./bin/* +bin diff --git a/makefile b/makefile new file mode 100755 index 0000000..45788f7 --- /dev/null +++ b/makefile @@ -0,0 +1,9 @@ +CC = gcc +CFLAGS = -o ./fmp -lraylib -O3 + +compile: ./src/Program.c ./src/linkedList.c + $(CC) $(CFLAGS) ./src/Program.c ./src/linkedList.c + +install: ./src/Program.c + $(CC) $(CFLAGS) ./src/Program.c + sudo cp ./fmp /bin/fmp diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..2464edc --- /dev/null +++ b/readme.md @@ -0,0 +1,15 @@ +# FMP - Fede Music Player + +### Pre-requisitos📓 + +Tener instalado: + +1. gcc +2. raylib + +### Instalación 🤓 + +i. Primero necesita correr un make para armar el binario del programa + +ii. Si la compilación es exitosa posiblemente quiera hacer un make install para copiar el binario compilado al /usr/bin + diff --git a/src/Program.c b/src/Program.c new file mode 100755 index 0000000..5cc626b --- /dev/null +++ b/src/Program.c @@ -0,0 +1,156 @@ +// Copyright (c) 2023 Federico Polidoro. All Rights Reserved. +#include +#include +#include + +#include "linkedList.h" + +#define HELP_EXIT() show_help_message(); return 0 + +void load_paths(struct linked_node** p, char** str, int cant){ + for (int i = cant; strcmp("-e", str[i]) != 0 && i > 0; i--) { + top_push(p,str[i]); + } +} + +void unload_paths(struct linked_node** p, int ind){ + for (int i = ind; i!=0; i--){ + top_pop(p); + } +} + +void show_help_message() { + printf(" FMP - Fede Music Player\n" + "//======================================// \n" + "// ./music [-e] [cancion1][cancion2].. // \n" + "//======================================// \n\n"); +} + +int main (int argc, char *argv[]) { + + if (argc<2) { HELP_EXIT(); } + if (strcmp("-h",argv[1]) == 0) { HELP_EXIT(); } + if (strcmp("--help",argv[1]) == 0) { HELP_EXIT(); } + + int ind = argc; + int correccion = 2; + + bool drag_and_drop = false; + if (strcmp("-e", argv[1]) == 0) { + drag_and_drop = true; + correccion++; + + } + + int selector = 0; + bool pause; + float timePlayed = 0.1f, lastTime = 0.0f; + + SetTraceLogLevel(LOG_ERROR); + InitWindow(400,200,"FMP - Fede Music Player"); + SetTargetFPS(60); + + + struct linked_node* path = NULL; + + load_paths(&path, argv, ind-1); + + //NOTE: this is for debugging + print_list(path); + // + + + InitAudioDevice(); + Music music = LoadMusicStream(get_value(path, selector)); + PlayMusicStream(music); + + while (!IsKeyReleased(KEY_Q)) { + + timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music); + + if (lastTime > timePlayed) { + StopMusicStream(music); + } + + if (!IsMusicStreamPlaying(music)) { + if(selector < ind-correccion){ + ++selector; + lastTime = 0.0f; + music = LoadMusicStream(get_value(path, selector)); + PlayMusicStream(music); + } + } + + lastTime = timePlayed; + UpdateMusicStream(music); + + if (IsKeyReleased(KEY_P)) { + pause = !pause; + if (pause == true) { + PauseMusicStream(music); + } else { + ResumeMusicStream(music); + } + } + + if (IsKeyReleased(KEY_R)) { + StopMusicStream(music); + PlayMusicStream(music); + lastTime = 0.0f; + } + + if (IsKeyReleased(KEY_LEFT)) { + if(selector > 0){ + --selector; + lastTime = 0.0f; + music = LoadMusicStream(get_value(path, selector)); + PlayMusicStream(music); + } + } + + if (IsKeyReleased(KEY_RIGHT)) { + if(selector < ind-correccion){ + ++selector; + lastTime = 0.0f; + music = LoadMusicStream(get_value(path, selector)); + PlayMusicStream(music); + } + } + +// NOTE: EXPERIMENTAL_FEATURE_BEGIN + if (IsFileDropped() && drag_and_drop) { + FilePathList droppedFiles = LoadDroppedFiles(); + + end_push(&path, droppedFiles.paths[0]); + ind++; + + selector = 0; + music = LoadMusicStream(get_value(path, selector)); + PlayMusicStream(music); + UnloadDroppedFiles(droppedFiles); + + //NOTE: this is for debugging + printf("\n\n"); + print_list(path); + // + } +// EXPERIMENTAL_FEATURE_END + + BeginDrawing(); + + ClearBackground(RAYWHITE); + DrawText("q = salir\np = pause/resume\nr = reset song\n<-/-> = change song", 20, 48, 20, DARKPURPLE); + DrawText(get_value(path, selector), 20, 180, 8, BLUE); + DrawRectangle(20, 20, 360, 12, LIGHTGRAY); + DrawRectangle(20, 20, (int)(timePlayed*360.0f), 12, MAROON); + + EndDrawing(); + } + + unload_paths(&path, ind); + + UnloadMusicStream(music); + CloseAudioDevice(); + CloseWindow(); + return 0; +} diff --git a/src/linkedList.c b/src/linkedList.c new file mode 100644 index 0000000..9dea883 --- /dev/null +++ b/src/linkedList.c @@ -0,0 +1,86 @@ +// Copyright (c) 2023 Federico Polidoro. All Rights Reserved. +#include "linkedList.h" + +void print_list(struct linked_node *p){ + while(p != NULL){ + printf("%s\n ",p->value); + p = p->next; + } +} + +char* get_value(struct linked_node *p ,int index){ + if( index == 0 ) return p->value; + while(index != 0){ + if(p->next->value != NULL && p != NULL){ + p = p->next; + --index; + }else{ + return "OUT OF RANGE"; + } + } + return p->value; +} + +void top_push(struct linked_node** head, char* str){ + struct linked_node* new_head; + new_head = (struct linked_node*)malloc(sizeof(struct linked_node)); + char* str2 = malloc(strlen(str)+1); + strcpy(str2, str); + new_head->value = str2; + new_head->next = *head; + *head = new_head; +} + +void end_push(struct linked_node** head, char* str){ + + char* str2 = malloc(strlen(str)+1); + strcpy(str2, str); + + if (*head == NULL){ + struct linked_node* new_head = (struct linked_node*)malloc(sizeof(struct linked_node)); + new_head->value = str2; + *head = new_head; + return; + } + + struct linked_node* new_head = malloc(sizeof(struct linked_node)); + new_head->value = str2; + + struct linked_node* p = *head; + while (p->next != NULL){ + p = p->next; + } + + p->next = new_head; +} + +char* top_pop(struct linked_node** head){ + char* devolucion = "head es nulo"; + if(*head == NULL) return devolucion; + if((*head)->value == NULL) return devolucion; + + struct linked_node* nnode = (*head)->next; + devolucion = (*head)->value; + + free((*head)->value); + free(*head); + *head = nnode; + return devolucion; +} + +char* end_pop(struct linked_node** head){ + char* devolucion = "end es nulo"; + + struct linked_node* lnode = *head; + + while(lnode->next != NULL){ + lnode = lnode->next; + } + + if(lnode != NULL){ + devolucion = lnode->value; + free(lnode->value); + free(lnode); + } + return devolucion; +} diff --git a/src/linkedList.h b/src/linkedList.h new file mode 100644 index 0000000..3a28250 --- /dev/null +++ b/src/linkedList.h @@ -0,0 +1,24 @@ +// Copyright (c) 2023 Federico Polidoro. All Rights Reserved. +#ifndef LINKEDLIST_H_ +#define LINKEDLIST_H_ + +#include +#include +#include + +struct linked_node { + char* value; + struct linked_node* next; +}; + +void print_list(struct linked_node*); + +char* get_value(struct linked_node* ,int); // este devuelve un valor dentro del + +void top_push(struct linked_node**, char*); // ingreso al inicio o final +void end_push(struct linked_node**, char*); + +char* top_pop(struct linked_node**); // elimino al inicio o final. +char* end_pop(struct linked_node**); + +#endif // LINKEDLIST_H_