add "Create Song from music file" function

This commit is contained in:
Chris Danford
2005-09-27 09:57:13 +00:00
parent ab8ed823b6
commit b9fe8abfea
+97
View File
@@ -8,6 +8,7 @@
#include "SmpackageExportDlg.h"
#include "onvertThemeDlg.h"
#include "ChangeGameSettings.h"
#include "RageUtil.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -43,6 +44,7 @@ BEGIN_MESSAGE_MAP(MainMenuDlg, CDialog)
ON_BN_CLICKED(IDC_EDIT_INSTALLATIONS, OnEditInstallations)
ON_BN_CLICKED(IDC_ANALYZE_ELEMENTS, OnAnalyzeElements)
ON_BN_CLICKED(IDC_CHANGE_API, OnChangeApi)
ON_BN_CLICKED(IDC_CREATE_SONG, OnCreateSong)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
@@ -77,3 +79,98 @@ void MainMenuDlg::OnChangeApi()
ChangeGameSettings dlg;
int nResponse = dlg.DoModal();
}
CString GetLastErrorString()
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Process any inserts in lpMsgBuf.
// ...
// Display the string.
CString s = (LPCTSTR)lpMsgBuf;
// Free the buffer.
LocalFree( lpMsgBuf );
return s;
}
void MainMenuDlg::OnCreateSong()
{
// TODO: Add your control notification handler code here
CFileDialog dialog (
TRUE, // file open?
NULL, // default file extension
NULL, // default file name
OFN_HIDEREADONLY | OFN_NOCHANGEDIR, // flags
"Music file (*.mp3;*.ogg)|*.mp3;*.ogg|||"
);
int iRet = dialog.DoModal();
CString sMusicFile = dialog.GetPathName();
if( iRet != IDOK )
return;
CString sFileNameNoExt, sExt, sThrowAway;
splitrelpath(
sMusicFile,
sThrowAway,
sFileNameNoExt,
sExt
);
BOOL bSuccess;
CString sSongDirectory = "Songs\\MyCreations\\";
CreateDirectory( sSongDirectory, NULL ); // ok if this fails. It will already exist if we've created another song.
DWORD dwError = ::GetLastError();
sSongDirectory += sFileNameNoExt;
bSuccess = CreateDirectory( sSongDirectory, NULL ); // CreateDirectory doesn't like a trailing slash
if( !bSuccess )
{
MessageBox( "Failed to song directory '" + sSongDirectory + "': " + GetLastErrorString() );
return;
}
sSongDirectory += "\\";
CString sNewMusicFile = sSongDirectory + sFileNameNoExt + "." + sExt;
bSuccess = CopyFile( sMusicFile, sNewMusicFile, TRUE );
if( !bSuccess )
{
MessageBox( "Failed to copy music file to '" + sNewMusicFile + "': " + GetLastErrorString() );
return;
}
// create a blank .sm file
CString sNewSongFile = sSongDirectory + sFileNameNoExt + ".sm";
FILE *fp = fopen( sNewSongFile, "w" );
if( fp == NULL )
{
MessageBox( "Failed to create the song file '" + sNewSongFile + "'" );
return;
}
fclose( fp );
MessageBox( "Success. Created the song '" + sSongDirectory + "'" );
}
BOOL MainMenuDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
TCHAR szCurDir[MAX_PATH];
GetCurrentDirectory( ARRAYSIZE(szCurDir), szCurDir );
GetDlgItem( IDC_EDIT_INSTALLATION )->SetWindowText( szCurDir );
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}