Skip to content

Commit

Permalink
dinamic music limit , limit of sound 200 , take any name file , reesc…
Browse files Browse the repository at this point in the history
…an folder funtion
  • Loading branch information
Kronos2308 committed Oct 10, 2019
1 parent c40580d commit 0d6d7f6
Showing 1 changed file with 81 additions and 24 deletions.
105 changes: 81 additions & 24 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ char fake_heap[HEAP_SIZE];
u32 music = 1;
u32 list = 0;
u32 isplay = 0;
u32 musiclimit = 0;
u32 prevmusic = 0;
char filename[32];

// we override libnx internals to do a minimal init
Expand Down Expand Up @@ -81,40 +83,80 @@ void __appInit(void)
}

void wakey()
{
audoutInitialize();
audoutStartAudioOut();


{ //Audio Thread
while (appletMainLoop())
{
// if (list <= 0){sprintf(filename, "StarDust/music/fondo.mp3");}

svcSleepThread(1000000000L);
// mp3MutInit();
if (music == 1){
if (music == 1)
{
isplay = 1;
sprintf(filename, "StarDust/music/%d.mp3", list);
if (file_exist(filename))
{
flash_led_connect();
// playMp3("StarDust/music/inputok.mp3");
playMp3(filename);
flash_led_connect();
playMp3(filename);
}
if(prevmusic == 0)
list++;
else
if(list <= 0)
list = musiclimit;
else
list--;
isplay = 0;
}

//limit of sounds, has (0...1...2).mp3
if (list >= 20){
list = 0;
}
//fix over
if (isplay >= 2){
isplay = 0;
}
//limit of sounds by list
if (list > musiclimit)
{
list = 0;
}
}
}

void Scan_folder(){
//List Audio and rename to use
musiclimit = 0;
DIR *dir;
struct dirent *ent;
dir = opendir("/StarDust/music");
while ((ent = readdir(dir)))
{
printf(ent->d_name);
char filename[272];
char destname[272];
musiclimit++;
flash_led_connect();
if(strlen(ent->d_name) > 6)
{
snprintf(filename, 272, "/StarDust/music/%s", ent->d_name);
for(int i = 0; i < 200; i ++)
{
//rename the mp3 for use
snprintf(destname, 272, "/StarDust/music/%d.mp3", i);
if (!file_exist(destname))
{
rename(filename, destname);
break;
}
}
}
}

musiclimit--;//ajust the use of 0.mp3
if(file_exist("StarDust/music/stop"))
musiclimit--;
if(file_exist("StarDust/music/pause"))
musiclimit--;
if (file_exist("StarDust/x.log"))
{
FILE *f;
f = fopen("StarDust/x.log", "w+");
fprintf(f,"---------------..\n");
fprintf(f, "music limit is %d ..\n",musiclimit);
fclose(f);
}
closedir(dir);
}

int main(int argc, char **argv)
Expand All @@ -124,11 +166,17 @@ int main(int argc, char **argv)
hidInitialize();
mp3MutInit();
// pauseInit();

unlink("/StarDust/music/pause");//just in case
audoutInitialize();
audoutStartAudioOut();
Scan_folder();

if (file_exist("StarDust/music/stop"))
{
music = 0;
}
unlink("/StarDust/music/pause");//just in case

Thread pauseThread;
Result rc = threadCreate(&pauseThread, wakey, NULL, 0x4000, 49, 3);
if (R_FAILED(rc))
Expand All @@ -142,6 +190,7 @@ int main(int argc, char **argv)
hidScanInput();
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);

//Stop
if (music == 1)
{
Expand All @@ -156,7 +205,7 @@ int main(int argc, char **argv)
}
}

//Pause
//Pause unestable
if ((kDown & KEY_R || kDown & KEY_L || kDown & KEY_X) && (kHeld & KEY_R && kHeld & KEY_L && kHeld & KEY_X)){
flash_led_connect();
if (music == 1)
Expand Down Expand Up @@ -195,8 +244,7 @@ int main(int argc, char **argv)
if ((kDown & KEY_ZL|| kDown & KEY_L) && (kHeld & KEY_ZL && kHeld & KEY_L)){
flash_led_connect();
music = 0;
list--;
list--;
prevmusic = 1;
create_flag("StarDust/music/stop");
audoutStopAudioOut();
while (appletMainLoop()){
Expand All @@ -205,10 +253,19 @@ int main(int argc, char **argv)
}
unlink("/StarDust/music/stop");
audoutStartAudioOut();
prevmusic = 0;
music = 1;
}
}

if (music == 0){
if ((kDown & KEY_ZL || kDown & KEY_ZR || kDown & KEY_Y) && (kHeld & KEY_ZL && kHeld & KEY_ZR && kHeld & KEY_Y)){
flash_led_connect();
Scan_folder();
}
}


//kill service
if ((kDown & KEY_LSTICK || kDown & KEY_RSTICK) && (kHeld & KEY_LSTICK && kHeld & KEY_RSTICK)){
break;}
Expand Down

0 comments on commit 0d6d7f6

Please sign in to comment.