-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
331 lines (254 loc) · 9.51 KB
/
main.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#include <wx/wxprec.h>
#include <wx/sound.h>
#include <wx/mediactrl.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/taskbar.h>
#include <C:\Users\Me\Downloads\bass24\c\bass.h>
#include <iostream>
#include <future>
#include <wx/filename.h>
using namespace std;
int isPlaying = 0;
HCHANNEL channel = NULL;
HSTREAM stream = NULL;
wxStaticText* staticText;
wxStaticText* staticText2;
bool isMediaLoaded = false;
wxStaticText* commentText;
wxPanel* panel_top;
wxSlider* VolumeSlider;
wxSlider* posSlider;
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
MyFrame();
private:
void OnHello(wxCommandEvent& event);
void OnExit(wxCommandEvent& event);
void OnPlaylist(wxCommandEvent& event);
int GetDuration(HSTREAM h);
void OnAbout(wxCommandEvent& event);
void Notify(wxTimerEvent& event);
void OnClose(wxCloseEvent& event);
void OnPositionChange(wxScrollEvent& event);
void OnVolChanged(wxScrollEvent& event);
};
enum
{
ID_Hello = 1,
ID_Playlist=2
};
enum controlIds
{
//some ids such as wxID_PLAY and wxID_STOP are standard ids but it is better to
//make our own custom ids because of the nature of the buttons we are creating
wxID_PLAYBUTTON = 1000,
wxID_STOPBUTTON,
wxID_PAUSE,
wxID_SEEKER,
wxID_MEDIACTRL,
wxID_PMEDIA,
wxID_TIMER,
wxID_VOLSLIDER,
wxID_PLAYLIST,
wxID_NEXT,
wxID_PREV,
wxID_SHUFFLE,
wxID_REPEAT,
wxID_AUTOSTART,
wxID_SHOWPLAYLIST,
wxID_HIDE,
wxID_FILEINFO,
wxID_CROSSFADETIMER,
ID_DUMMYVALUE
};
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
MyFrame* frame = new MyFrame();
frame->Show(true);
return true;
wxTimer* myTimer = new wxTimer(this, 1);
}
MyFrame::MyFrame()
: wxFrame(NULL, wxID_ANY, "Elm Player")
{
wxMenu* playBackMenu = new wxMenu();
playBackMenu->AppendCheckItem(wxID_SHUFFLE, "Shuffle\tCtrl+S", "Play in shuffle mode");
playBackMenu->AppendCheckItem(wxID_REPEAT, "Repeat\tCtrl+R", "Repeat playing track");
playBackMenu->Append(wxID_NEXT, "Next\tCtrl+N", "Skip to next track");
playBackMenu->Append(wxID_PREV, "Previous\tCtrl+P");
playBackMenu->Append(wxID_PLAYBUTTON, "Play\tSPACE");
playBackMenu->Append(wxID_STOPBUTTON, "Stop\tCtrl+T");
wxMenu* menuFile = new wxMenu;
menuFile->Append(ID_Hello, "&Choose song...\tCtrl-H",
"Find a song to play");
menuFile->AppendSeparator();
menuFile->Append(wxID_EXIT);
wxMenu* menuHelp = new wxMenu;
menuHelp->Append(wxID_ABOUT);
wxMenuBar* menuBar = new wxMenuBar; // creating the main menu
menuBar->Append(menuFile, "&File");
wxMenu* menuPlaylist = new wxMenu; //creating the playlist main menu
menuPlaylist->Append(ID_Playlist, "&View Playlist");
menuBar->Append(menuPlaylist,"&Playlist");
menuBar->Append(menuHelp, "&Help");
menuFile->AppendSeparator();
menuBar->Append(playBackMenu, "&Playback");
SetMenuBar(menuBar);
//SetIcon(wxIcon icon2(wxT("icon2")););
SetIcon(wxIcon(wxT("tree.ico"), wxBITMAP_TYPE_ICO, 16, 16));
CreateStatusBar();
SetStatusText("Welcome to Elm Player!");
SetBackgroundColour(wxColour(255,255,255));
wxString test = wxT("Choose a file");
panel_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(600, 400));
panel_top->SetBackgroundColour(wxColor(0, 200, 0));
wxFont myFont(12, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
panel_top->SetFont(myFont);
wxPanel* panel_bottom = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(400, 20));
panel_bottom->SetBackgroundColour(wxColor(204, 204, 204));
VolumeSlider = new wxSlider(panel_bottom, wxID_VOLSLIDER, 16, 0, 100,
wxPoint(0, 0), wxSize(200, -1),
wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS);
//int currentSonglen=GetDuration(stream);
posSlider = new wxSlider(panel_bottom, 190, 0, 0, 800,
wxPoint(0, 100), wxSize(400, -1),
wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS);
//posSlider->Hide();
wxBoxSizer* sizer2 = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* mediaControls = new wxBoxSizer(wxHORIZONTAL);
sizer2->Add(mediaControls, 0, wxALL, 5);
staticText = new wxStaticText(panel_top, wxID_ANY, wxT(""), wxPoint(0, 30));
commentText = new wxStaticText(panel_top, wxID_ANY, wxT("Song description"), wxPoint(0, 70));
Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
Bind(wxEVT_MENU, &MyFrame::OnPlaylist, this, ID_Playlist);
Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
Bind(wxEVT_TIMER, &MyFrame::Notify, this);
Connect(190, wxEVT_SLIDER,wxScrollEventHandler(MyFrame::OnPositionChange));
Connect(wxID_VOLSLIDER, wxEVT_SLIDER, wxScrollEventHandler(MyFrame::OnVolChanged));
Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(MyFrame::OnClose), NULL, this);
wxBoxSizer* bSizer = new wxBoxSizer(wxVERTICAL);
wxSizer* sizerBottom = new wxBoxSizer(wxHORIZONTAL);
bSizer->Add(panel_top, 1, wxEXPAND|wxLEFT|wxTOP|wxRIGHT,10);
bSizer->Add(panel_bottom, 1, wxALIGN_CENTER , 1);
panel_bottom->SetSizer(sizer2);
panel_bottom->Layout();
sizer2->Fit(panel_bottom);
SetSizerAndFit(bSizer);
}
void MyFrame::OnExit(wxCommandEvent& event)
{
Close(true);
Destroy();
wxWindow::Close();
}
int MyFrame::GetDuration(HSTREAM h) {
QWORD len = BASS_ChannelGetLength(h, BASS_POS_BYTE); // the length in bytes
int timeR = BASS_ChannelBytes2Seconds(h, len); // the length in seconds
//wxStaticText* staticText2 = new wxStaticText(panel_top, wxID_ANY, wxT(""), wxPoint(0, 44));
return timeR;
}
void MyFrame::OnPlaylist(wxCommandEvent& event)
{
wxMessageBox("This is the playlist page",
"About Hello World", wxOK | wxICON_INFORMATION);
}
void MyFrame::OnAbout(wxCommandEvent& event)
{
wxMessageBox("This is a wxWidgets Hello World example",
"About Hello World", wxOK | wxICON_INFORMATION);
}
void MyFrame::OnHello(wxCommandEvent& event)
{
wxString defaultDir = wxT("C:\\Users\\%USERPROFILE%\\");
wxString defaultFilename = wxEmptyString;
wxString caption = wxT("Choose a file");
wxString wildcard = "MP3 Files (*.mp3) | *.mp3";
wxString path="";
wxString songName = "";
wxFileDialog dialog(NULL, caption, defaultDir, defaultFilename,
wildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (dialog.ShowModal() == wxID_OK)
{
//posSlider->Show();
if (isPlaying == 1) {
BASS_ChannelFree(stream);
BASS_ChannelSetPosition(stream, 0, BASS_POS_BYTE);
QWORD tpos = BASS_ChannelGetPosition(stream, BASS_POS_BYTE);
int trealPos = BASS_ChannelBytes2Seconds(stream, tpos);
wxString theSongLength = wxString::Format(wxT("%i"), trealPos);
staticText2->SetLabel("Inside:" + trealPos);
}
//isPlaying = 1;
BASS_ChannelFree(stream);
path = "";
wxTimer* myTimer = new wxTimer(this, 1);
myTimer->SetOwner(this, 1);
isPlaying = 1;
path = "" + dialog.GetPath();
songName = wxFileName(path).GetName();
staticText->SetLabel(""+songName);
BASS_Init(-1, 44100, 0, 0, NULL);
BASS_SetVolume(.02);
HSAMPLE sample = BASS_SampleLoad(false, path.char_str(), 0, 0, 1, BASS_SAMPLE_MONO);
stream = BASS_StreamCreateFile(FALSE, path.char_str(), 0, 0, 0);
myTimer->Start();
channel = BASS_SampleGetChannel(stream, FALSE);
BASS_ChannelPlay(stream, TRUE);
staticText2 = new wxStaticText(panel_top, wxID_ANY, wxT(""), wxPoint(0, 45));
isMediaLoaded = true;
const char* comments = BASS_ChannelGetTags(channel, BASS_TAG_OGG); // get a pointer to the 1st comment
if (comments) {
wxMessageBox(comments);
}
int filterIndex = dialog.GetFilterIndex();
}
}
void MyFrame::Notify(wxTimerEvent& event) {
int realPos;
QWORD pos = BASS_ChannelGetPosition(stream, BASS_POS_BYTE);
realPos = BASS_ChannelBytes2Seconds(stream, pos);
wxString theSongLength = wxString::Format(wxT("%i"), realPos);
staticText2->SetLabel(theSongLength);
//double volume = static_cast<double>(VolumeSlider->GetValue());
int posT = (posSlider->GetValue());
int offset = posT - realPos;
double volume = static_cast<double>(VolumeSlider->GetValue());
BASS_SetVolume(volume / 100);
if (isPlaying == 1) {
posSlider->SetValue(realPos); //movesCursor to music
posSlider->SetMax(GetDuration(stream));
}
//BASS_ChannelSetAttribute(stream, BASS_ATTRIB_VOL, volume);
}
void MyFrame::OnVolChanged(wxScrollEvent& event) {
//wxMessageBox("Slider Vol moved");
double volume = static_cast<double>(VolumeSlider->GetValue());
BASS_SetVolume(volume / 100);
}
void MyFrame::OnPositionChange(wxScrollEvent& event)
{
//wxMessageBox("Slider Pos moved");
int realPos;
QWORD pos = BASS_ChannelGetPosition(stream, BASS_POS_BYTE);
realPos = BASS_ChannelBytes2Seconds(stream, pos);
int posT = (posSlider->GetValue());
int offset = posT - realPos;
QWORD loc;
loc = BASS_ChannelSeconds2Bytes(stream, posT);
BASS_ChannelSetPosition(stream, loc, BASS_POS_BYTE);
BASS_ChannelPlay(stream, FALSE);
}
void MyFrame::OnClose(wxCloseEvent& event)
{
Destroy();
}