/
RiffWavToMp3.cpp
168 lines (129 loc) · 3.43 KB
/
RiffWavToMp3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
** CDex - Open Source Digital Audio CD Extractor
**
** Copyright (C) 2006 - 2007 Georgy Berdyshev
** Copyright (C) 1999 - 2007 Albert L. Faber
**
** http://cdexos.sourceforge.net/
** http://sourceforge.net/projects/cdexos
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StdAfx.h"
#include "RiffWavToMP3.h"
#include "AudioFile.h"
#define TIMERID 2
#define TIMERSLOT 100
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRiffWavToMP3 dialog
// CONSTRUCTOR
CRiffWavToMP3::CRiffWavToMP3(CWnd* pParent /*=NULL*/)
: CDialog(CRiffWavToMP3::IDD, pParent)
{
//{{AFX_DATA_INIT(CRiffWavToMP3)
//}}AFX_DATA_INIT
m_pFileDlg=NULL;
}
// DESCTURCTOR
CRiffWavToMP3::~CRiffWavToMP3()
{
delete m_pFileDlg;
}
// ON_WM_TIMER()
void CRiffWavToMP3::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRiffWavToMP3)
DDX_Control(pDX, IDC_PROGRESS, m_Progress);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_PROCESSFILENAME, m_processingFile);
}
BEGIN_MESSAGE_MAP(CRiffWavToMP3, CDialog)
//{{AFX_MSG_MAP(CRiffWavToMP3)
ON_WM_TIMER()
ON_BN_CLICKED(IDABORT, OnAbort)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRiffWavToMP3 message handlers
void CRiffWavToMP3::OnCancel()
{
KillTimer(TIMERID);
CDialog::OnCancel();
}
void CRiffWavToMP3::OnTimer(UINT nIDEvent)
{
// Obtain the number of files
if (m_Pos!=NULL)
{
// Get the file name to be converted
CUString strFileName=m_pFileDlg->GetNextPathName(m_Pos);
CUString strOrig(strFileName);
// Update progress bar
m_Progress.SetPos(m_nCurFile++);
// Set current file name
CUStringConvert strCnv;
m_processingFile.SetWindowText( strCnv.ToT( strFileName ) );
// Update controls
UpdateData(FALSE);
CWAV myWav;
// Strip extension
int nPos=strFileName.ReverseFind('.');
// Stip it
if (nPos>0)
strFileName=strFileName.Left(nPos);
// Do the conversion
if (myWav.StripRiffWavHeader(strFileName)==CDEX_OK)
{
// delete the original file?
if (m_pFileDlg->m_bDeleteOriginal)
CDexDeleteFile(strOrig);
}
}
else
{
OnCancel();
}
CDialog::OnTimer(nIDEvent);
}
BOOL CRiffWavToMP3::OnInitDialog()
{
CDialog::OnInitDialog();
// translate dialog resources
g_language.InitDialogStrings( this, IDD );
// Get start position
m_Pos=m_pFileDlg->GetStartPosition();
m_nTotalFiles=0;
// Obtain the number of files
while (m_Pos!=NULL)
{
m_nTotalFiles++;
m_pFileDlg->GetNextPathName(m_Pos);
}
// Get start position again
m_Pos=m_pFileDlg->GetStartPosition();
m_Progress.SetRange(0,m_nTotalFiles);
m_nCurFile=0;
SetTimer(TIMERID,TIMERSLOT,NULL);
return TRUE;
}
void CRiffWavToMP3::OnAbort()
{
OnCancel();
}