Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
fedpo2 committed Sep 16, 2023
2 parents 28c5e95 + 712f00a commit 9a0f2a0
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions src/Program.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define HELP_EXIT() show_help_message(); return 0

void load_paths(struct linked_node** p, char** str, int cant){
for (int i = cant; i>0; i--) {
for (int i = cant; strcmp("-e", str[i]) != 0 && i > 0; i--) {
top_push(p,str[i]);
}
}
Expand All @@ -19,33 +19,41 @@ void unload_paths(struct linked_node** p, int ind){
}
}


void show_help_message() {
printf(" FMP - Fede Music Player\n"
"//=================================// \n"
"// ./music [cancion1][cancion2].. // \n"
"//=================================// \n\n");
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, argc-1);
int ind = argc;
load_paths(&path, argv, ind-1);

//NOTE: this is for debugging
print_list(path);
Expand All @@ -60,22 +68,19 @@ int main (int argc, char *argv[]) {

timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music);

//chequea que el tiempo de reproduccion de la musica no sea más larga que la cancion
if (timePlayed > 1.0f) {
timePlayed = 1.0f;
if (lastTime > timePlayed) {
StopMusicStream(music);
}

if (timePlayed < lastTime) {
if (selector != argc-1) {
selector++;
} else {
selector = 1;
if (!IsMusicStreamPlaying(music)) {
if(selector < ind-correccion){
++selector;
lastTime = 0.0f;
music = LoadMusicStream(get_value(path, selector));
PlayMusicStream(music);
}
lastTime = 0.0f;
music = LoadMusicStream(get_value(path, selector));
PlayMusicStream(music);
}

lastTime = timePlayed;
UpdateMusicStream(music);

Expand Down Expand Up @@ -104,15 +109,16 @@ int main (int argc, char *argv[]) {
}

if (IsKeyReleased(KEY_RIGHT)) {
if(selector < ind-2){
if(selector < ind-correccion){
++selector;
lastTime = 0.0f;
music = LoadMusicStream(get_value(path, selector));
PlayMusicStream(music);
}
}

if (IsFileDropped()) {

// NOTE: EXPERIMENTAL_FEATURE_BEGIN
if (IsFileDropped() && drag_and_drop) {
FilePathList droppedFiles = LoadDroppedFiles();

end_push(&path, droppedFiles.paths[0]);
Expand All @@ -127,8 +133,8 @@ int main (int argc, char *argv[]) {
printf("\n\n");
print_list(path);
//

}
// EXPERIMENTAL_FEATURE_END

BeginDrawing();

Expand Down

0 comments on commit 9a0f2a0

Please sign in to comment.