mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-18 09:19:17 +01:00
*Added MP3 functions and MP3 Menu
DON'T USE IT ITS STILL BUGGY. DON'T MAKE ISSUES ABOUT IT.
This commit is contained in:
parent
557f82d138
commit
bcff8dfd58
3
Makefile
3
Makefile
@ -31,13 +31,12 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80a00
|
||||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lfat -lpngu -lpng -lmetaphrasis -lm -lz -lwiiuse -lbte -lasnd -logc -ltremor -lfreetype
|
||||
LIBS := -lfat -lpngu -lpng -lmetaphrasis -lm -lz -lwiiuse -lmad -lbte -lasnd -logc -ltremor -lfreetype
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(DEVKITPPC)/lib $(CURDIR)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
|
File diff suppressed because one or more lines are too long
2
gui.pnps
2
gui.pnps
@ -1 +1 @@
|
||||
<pd><ViewState><e p="gui" x="true"></e><e p="gui\source" x="true"></e><e p="gui\source\fonts" x="false"></e><e p="gui\source\images" x="false"></e><e p="gui\source\libwbfs" x="false"></e><e p="gui\source\libwiigui" x="true"></e><e p="gui\source\sounds" x="false"></e></ViewState></pd>
|
||||
<pd><ViewState><e p="gui" x="true"></e><e p="gui\source" x="true"></e><e p="gui\source\fonts" x="false"></e><e p="gui\source\images" x="false"></e><e p="gui\source\libwbfs" x="false"></e><e p="gui\source\libwiigui" x="true"></e><e p="gui\source\mp3lib" x="false"></e><e p="gui\source\sounds" x="false"></e></ViewState></pd>
|
@ -7,8 +7,8 @@ class customOptionList {
|
||||
value = new char * [size];
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
name[i] = new char[30];
|
||||
value[i] = new char[20];
|
||||
name[i] = new char[40];
|
||||
value[i] = new char[40];
|
||||
}
|
||||
length = size;
|
||||
};
|
||||
|
141
source/menu.cpp
141
source/menu.cpp
@ -39,6 +39,7 @@
|
||||
#include "cfg.h"
|
||||
#include "libwiigui/gui_customoptionbrowser.h"
|
||||
#include "libwiigui/gui_gamebrowser.h"
|
||||
#include "mp3s.h"
|
||||
|
||||
#define MAX_CHARACTERS 38
|
||||
|
||||
@ -3412,7 +3413,7 @@ static int MenuSettings()
|
||||
tabBtn.SetImage(&tab1Img);
|
||||
|
||||
|
||||
|
||||
|
||||
GuiButton page1Btn(40, 96);
|
||||
page1Btn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
page1Btn.SetPosition(-202, 90);
|
||||
@ -3532,7 +3533,7 @@ static int MenuSettings()
|
||||
page2Btn.SetTrigger(2, &trigR);
|
||||
page3Btn.SetTrigger(1, &trigMinus);
|
||||
page3Btn.SetTrigger(2, &trigL);
|
||||
|
||||
|
||||
|
||||
mainWindow->Append(&w);
|
||||
mainWindow->Append(&optionBrowser2);
|
||||
@ -3590,7 +3591,7 @@ static int MenuSettings()
|
||||
mainWindow->Append(&page1Btn);
|
||||
mainWindow->Append(&page3Btn);
|
||||
|
||||
sprintf(options2.name[0], " ");
|
||||
sprintf(options2.name[0], "MP3 Menu");
|
||||
sprintf(options2.name[1], " ");
|
||||
sprintf(options2.name[2], " ");
|
||||
sprintf(options2.name[3], "Under");
|
||||
@ -3600,6 +3601,8 @@ static int MenuSettings()
|
||||
sprintf(options2.name[7], " ");
|
||||
sprintf(options2.name[8], " ");
|
||||
|
||||
|
||||
|
||||
}
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
@ -3980,6 +3983,18 @@ static int MenuSettings()
|
||||
sprintf(options2.value[6], " ");
|
||||
sprintf(options2.value[7], " ");
|
||||
sprintf(options2.value[8], " ");
|
||||
|
||||
ret = optionBrowser2.GetClickedOption();
|
||||
|
||||
switch(ret) {
|
||||
|
||||
case 0:
|
||||
menu = MENU_MP3;
|
||||
pageToDisplay = 0;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(shutdown == 1)
|
||||
@ -4045,6 +4060,7 @@ static int MenuSettings()
|
||||
// mainWindow->Remove(&page2Btn);
|
||||
w.Remove(&backBtn);
|
||||
w.Remove(&lockBtn);
|
||||
w.Remove(&tabBtn);
|
||||
char entered[20] = "";
|
||||
int result = OnScreenKeyboard(entered, 20,0);
|
||||
// mainWindow->Append(&page1Btn);
|
||||
@ -4052,6 +4068,7 @@ static int MenuSettings()
|
||||
mainWindow->Append(&optionBrowser2);
|
||||
w.Append(&backBtn);
|
||||
w.Append(&lockBtn);
|
||||
w.Append(&tabBtn);
|
||||
if ( result == 1 )
|
||||
{
|
||||
if (!strcmp(entered, Settings.unlockCode)) //if password correct
|
||||
@ -4375,6 +4392,8 @@ int GameSettings(struct discHdr * header)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* MenuCheck
|
||||
***************************************************************************/
|
||||
@ -4487,6 +4506,119 @@ static int MenuCheck()
|
||||
return menu;
|
||||
}
|
||||
|
||||
int MenuMp3()
|
||||
{
|
||||
int menu = MENU_NONE, cnt = 0;
|
||||
int ret = 0;
|
||||
int scrollon, i = 0;
|
||||
|
||||
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM, vol);
|
||||
GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, SOUND_PCM, vol);
|
||||
|
||||
GuiTrigger trigA;
|
||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
|
||||
customOptionList options2(500);
|
||||
char mp3path[30] = "SD:/mp3/";
|
||||
char fullpath[100];
|
||||
int countmp3 = GetFiles(mp3path);
|
||||
|
||||
for (cnt = 0; cnt < countmp3; cnt++) {
|
||||
snprintf(options2.value[cnt], 30, "%s", mp3files[cnt]);
|
||||
sprintf (options2.name[cnt],"%i.", cnt+1);
|
||||
}
|
||||
options2.length = cnt;
|
||||
|
||||
GuiImageData btnOutline(settings_menu_button_png);
|
||||
if(cnt < 9) {
|
||||
scrollon = 0;
|
||||
} else {
|
||||
scrollon = 1;
|
||||
}
|
||||
GuiCustomOptionBrowser optionBrowser4(396, 280, &options2, CFG.theme_path, "bg_options_settings", bg_options_settings_png, scrollon);
|
||||
optionBrowser4.SetPosition(0, 90);
|
||||
optionBrowser4.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
optionBrowser4.SetCol2Position(65);
|
||||
|
||||
GuiText cancelBtnTxt("Back", 22, (GXColor){0, 0, 0, 255});
|
||||
cancelBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30);
|
||||
GuiImage cancelBtnImg(&btnOutline);
|
||||
if (Settings.wsprompt == yes){
|
||||
cancelBtnImg.SetWidescreen(CFG.widescreen);}
|
||||
GuiButton cancelBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
|
||||
cancelBtn.SetScale(0.9);
|
||||
cancelBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
cancelBtn.SetPosition(180, 400);
|
||||
cancelBtn.SetLabel(&cancelBtnTxt);
|
||||
cancelBtn.SetImage(&cancelBtnImg);
|
||||
cancelBtn.SetSoundOver(&btnSoundOver);
|
||||
cancelBtn.SetTrigger(&trigA);
|
||||
cancelBtn.SetEffectGrow();
|
||||
|
||||
GuiText playBtnTxt("Play", 22, (GXColor){0, 0, 0, 255});
|
||||
cancelBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30);
|
||||
GuiImage playBtnImg(&btnOutline);
|
||||
if (Settings.wsprompt == yes){
|
||||
cancelBtnImg.SetWidescreen(CFG.widescreen);}
|
||||
GuiButton playBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
|
||||
playBtn.SetScale(0.9);
|
||||
playBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
playBtn.SetPosition(-180, 400);
|
||||
playBtn.SetLabel(&playBtnTxt);
|
||||
playBtn.SetImage(&playBtnImg);
|
||||
playBtn.SetSoundOver(&btnSoundOver);
|
||||
playBtn.SetTrigger(&trigA);
|
||||
playBtn.SetEffectGrow();
|
||||
|
||||
HaltGui();
|
||||
GuiWindow w(screenwidth, screenheight);
|
||||
w.Append(&cancelBtn);
|
||||
w.Append(&playBtn);
|
||||
mainWindow->Append(&optionBrowser4);
|
||||
mainWindow->Append(&w);
|
||||
|
||||
ResumeGui();
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
if (cancelBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
menu = MENU_DISCLIST;
|
||||
CloseMp3();
|
||||
bgMusic->Play();
|
||||
break;
|
||||
}
|
||||
|
||||
ret = optionBrowser4.GetClickedOption();
|
||||
|
||||
for(i = 0; i < countmp3; i++) {
|
||||
if(i == ret) {
|
||||
sprintf(fullpath,"%s%s", mp3path,mp3files[ret]);
|
||||
PlayMp3(fullpath);
|
||||
SetMp3Volume(127);
|
||||
}
|
||||
}
|
||||
|
||||
if (playBtn.GetState() == STATE_CLICKED) {
|
||||
|
||||
ret = optionBrowser4.GetSelectedOption();
|
||||
sprintf(fullpath,"%s%s", mp3path,mp3files[ret]);
|
||||
//bgMusic->Stop();
|
||||
PlayMp3(fullpath);
|
||||
SetMp3Volume(127);
|
||||
playBtn.ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
HaltGui();
|
||||
mainWindow->Remove(&optionBrowser4);
|
||||
mainWindow->Remove(&w);
|
||||
ResumeGui();
|
||||
return menu;
|
||||
|
||||
|
||||
return menu;
|
||||
}
|
||||
/****************************************************************************
|
||||
* MainMenu
|
||||
***************************************************************************/
|
||||
@ -4549,6 +4681,9 @@ int MainMenu(int menu)
|
||||
case MENU_DISCLIST:
|
||||
currentMenu = MenuDiscList();
|
||||
break;
|
||||
case MENU_MP3:
|
||||
currentMenu = MenuMp3();
|
||||
break;
|
||||
default: // unrecognized menu
|
||||
currentMenu = MenuCheck();
|
||||
break;
|
||||
|
@ -24,7 +24,8 @@ enum
|
||||
MENU_FORMAT,
|
||||
MENU_INSTALL,
|
||||
MENU_CHECK,
|
||||
MENU_GAME_SETTINGS
|
||||
MENU_GAME_SETTINGS,
|
||||
MENU_MP3
|
||||
};
|
||||
|
||||
#endif
|
||||
|
131
source/mp3s.c
Normal file
131
source/mp3s.c
Normal file
@ -0,0 +1,131 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <math.h>
|
||||
#include <gccore.h>
|
||||
#include <wiiuse/wpad.h>
|
||||
#include <fat.h>
|
||||
#include <sys/dir.h>
|
||||
#include <unistd.h>
|
||||
#include <mp3player.h>
|
||||
|
||||
#include "mp3s.h"
|
||||
|
||||
char filename[80];
|
||||
|
||||
//Files
|
||||
FILE* pFile;
|
||||
|
||||
|
||||
s32 my_reader(void *fp,void *dat, s32 size)
|
||||
{
|
||||
return fread(dat, 1, size, fp);
|
||||
}
|
||||
|
||||
|
||||
void StopMp3()
|
||||
{
|
||||
if(MP3Player_IsPlaying()) {
|
||||
MP3Player_Stop();
|
||||
}
|
||||
}
|
||||
|
||||
void CloseMp3() {
|
||||
|
||||
if(MP3Player_IsPlaying()) {
|
||||
MP3Player_Stop();
|
||||
}
|
||||
fclose(pFile);
|
||||
}
|
||||
|
||||
void SetMp3Volume(u32 vol)
|
||||
{
|
||||
MP3Player_Volume(vol);
|
||||
}
|
||||
|
||||
int PlayMp3(char * path) {
|
||||
|
||||
if(!MP3Player_IsPlaying()) {
|
||||
MP3Player_Init();
|
||||
} else {
|
||||
StopMp3();
|
||||
}
|
||||
|
||||
pFile = fopen (path, "r");
|
||||
MP3Player_PlayFile(pFile, my_reader, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
int PlayMp3(char * path)
|
||||
{
|
||||
|
||||
|
||||
if(!MP3Player_IsPlaying()) {
|
||||
MP3Player_Init();
|
||||
} else {
|
||||
MP3Player_Stop();
|
||||
}
|
||||
long lSize = 0;
|
||||
char * buffermp3 = NULL;
|
||||
size_t resultmp3;
|
||||
|
||||
pFile = fopen (path, "r");
|
||||
|
||||
//Check that pFile exist
|
||||
if (pFile!=NULL)
|
||||
{
|
||||
// obtain file size:
|
||||
fseek (pFile , 0 , SEEK_END);
|
||||
lSize = ftell (pFile);
|
||||
rewind (pFile);
|
||||
|
||||
// allocate memory to contain the whole file:
|
||||
buffermp3 = (char*) malloc (sizeof(char)*lSize);
|
||||
if (buffermp3 == NULL) {fputs (" Memory error",stderr); exit (2);}
|
||||
|
||||
// copy the file into the buffer:
|
||||
resultmp3 = fread (buffermp3,1,lSize,pFile);
|
||||
if (resultmp3 != lSize) {fputs (" Reading error",stderr); exit (3);}
|
||||
|
||||
|
||||
fclose (pFile);
|
||||
}
|
||||
|
||||
if (buffermp3 != NULL)
|
||||
{
|
||||
MP3Player_PlayBuffer(buffermp3,lSize,NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
int GetFiles(char * mp3path)
|
||||
{
|
||||
int countmp3 = 0;
|
||||
|
||||
struct stat st;
|
||||
DIR_ITER* dir;
|
||||
dir = diropen (mp3path);
|
||||
|
||||
if (dir == NULL) //If empty
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (dirnext(dir,filename,&st) == 0)
|
||||
{
|
||||
if ((st.st_mode & S_IFDIR) == 0)
|
||||
{
|
||||
// st.st_mode & S_IFDIR indicates a directory
|
||||
sprintf(mp3files[countmp3], "%s", filename);
|
||||
countmp3++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return countmp3;
|
||||
}
|
22
source/mp3s.h
Normal file
22
source/mp3s.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef _MP3S_H_
|
||||
#define _MP3S_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
char mp3files[500][30];
|
||||
|
||||
void StopMp3();
|
||||
void SetMp3Volume(u32 vol);
|
||||
int PlayMp3(char * path);
|
||||
int OpenMp3(char * path);
|
||||
void CloseMp3();
|
||||
int GetFiles(char * mp3path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user