Merge branch 'dev'
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# ignora la carpeta de compilados
|
||||
./bin/*
|
||||
bin
|
||||
9
makefile
Executable file
9
makefile
Executable file
@@ -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
|
||||
15
readme.md
Normal file
15
readme.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# FMP - Fede Music Player
|
||||
|
||||
### Pre-requisitos📓
|
||||
|
||||
Tener instalado:
|
||||
|
||||
1. gcc
|
||||
2. raylib
|
||||
|
||||
### Instalación 🤓
|
||||
|
||||
i. Primero necesita correr un <kbd>make</kbd> para armar el binario del programa
|
||||
|
||||
ii. Si la compilación es exitosa posiblemente quiera hacer un <kbd>make install</kbd> para copiar el binario compilado al <kbd>/usr/bin</kbd>
|
||||
|
||||
156
src/Program.c
Executable file
156
src/Program.c
Executable file
@@ -0,0 +1,156 @@
|
||||
// Copyright (c) 2023 Federico Polidoro. All Rights Reserved.
|
||||
#include <raylib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
86
src/linkedList.c
Normal file
86
src/linkedList.c
Normal file
@@ -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;
|
||||
}
|
||||
24
src/linkedList.h
Normal file
24
src/linkedList.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2023 Federico Polidoro. All Rights Reserved.
|
||||
#ifndef LINKEDLIST_H_
|
||||
#define LINKEDLIST_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
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_
|
||||
Reference in New Issue
Block a user