/
VorbitalDlg.cpp
841 lines (750 loc) · 22.9 KB
/
VorbitalDlg.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
#include "VorbitalDlg.h"
#include "SettingsDlg.h"
#ifdef WIN32
#include "alut.h"
#else
#include <sys/stat.h>
#include <unistd.h>
#endif
#include <QFile>
#include <QMessageBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QFileDialog>
#include <QBitmap>
#include <QSettings>
#include <QStringList>
#include <QMetaMethod>
#include <QCloseEvent>
#include <QDebug>
#include <QMimeData>
#include "add.xpm"
#include "folder.xpm"
#include "forward.xpm"
// For the settings dialog.
//#include "gear.xpm"
#include "normal.xpm"
#include "null.xpm"
#include "pause.xpm"
#include "play.xpm"
#include "question.xpm"
#include "random.xpm"
#include "remove.xpm"
#include "reverse.xpm"
#include "stop.xpm"
VorbitalDlg::~VorbitalDlg()
{
}
/*!
* VorbitalDlg creator
*/
VorbitalDlg::VorbitalDlg( )
{
qDebug() << "VorbitalDlg Create.";
_done = false;
// OpenAL Initialization
#ifdef WIN32
alutInit(NULL, 0);
#else
_device = alcOpenDevice(NULL);
_context = alcCreateContext(_device, NULL);
alcMakeContextCurrent(_context);
#endif
alGetError();
// Initialize position of the Listener.
ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 };
// Velocity of the Listener.
ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };
// Orientation of the Listener. (first 3 elements are "at", second 3 are "up")
// Also note that these should be units of '1'.
ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
alListenerfv(AL_POSITION, ListenerPos);
alListenerfv(AL_VELOCITY, ListenerVel);
alListenerfv(AL_ORIENTATION, ListenerOri);
_listPosition = 0;
_musicStream = NULL;
_btnBrowse = NULL;
_btnBrowseFolder = NULL;
_btnPlay = NULL;
_btnStop = NULL;
_btnPause = NULL;
_btnForward = NULL;
_btnReverse = NULL;
_btnClear = NULL;
_btnRemove = NULL;
_btnSettings = NULL;
_btnAbout = NULL;
_btnRandomize = NULL;
_txtSampleRate = NULL;
_txtVersion = NULL;
_txtBitRate = NULL;
_txtChannels = NULL;
_txtComment = NULL;
_txtTime = NULL;
_volumeSlider = NULL;
_timeElapsed = 0;
qDebug() << "Setting VorbitalDlg play state to STOPPED.";
_playState = STOPPED;
_incrementNeeded = true;
_randomize = false;
_menuDoubleClicked = false;
srand((unsigned)time(0));
CreateControls();
LoadSettings();
QIcon icon("vorbital.ico");
setWindowIcon(icon);
setWindowTitle("Vorbital Player");
// Start up the playlist thread.
_playlistThread = new PlaylistThread(this);
_playlistThread->start();
}
void VorbitalDlg::LoadSettings()
{
QSettings* configData = new QSettings("Zeta Centauri", "Vorbital Player");
qDebug() << "LoadSettings loading file " << configData->fileName() << ".";
// Randomizer setting.
_randomize = configData->value( "randomize" ).toInt();
if( _randomize )
{
_btnRandomize->setIcon(QPixmap(random_xpm));
}
else
{
_btnRandomize->setIcon(QPixmap(normal_xpm));
}
// Volume setting.
_volumeSlider->setValue((configData->value( "volume" )).toInt());
int volume = _volumeSlider->value();
float actualVol = (float)volume / 100.0f;
if( _musicStream != NULL )
{
_musicStream->SetVolume( actualVol );
}
// Window size.
int sizex = (configData->value( "sizex" )).toInt();
int sizey = (configData->value( "sizey" )).toInt();
if( sizex > 0 && sizey > 0 )
{
setFixedSize(sizex, sizey);
setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
}
// Previous playlist.
QString songs = configData->value("playlist").toString();
QStringList songList = songs.split(";");
for( int i = 0; i < songList.count(); i++ )
{
if( songList[i].length() < 2 )
{
continue;
}
QFileInfo info(songList[i]);
QListWidgetItem* item = new QListWidgetItem(info.baseName());
item->setData(Qt::UserRole, QVariant(info.absoluteFilePath()));
qDebug() << "Adding to playlist: " << songList[i];
_lstPlaylist->addItem(item);
}
qDebug() << "Loaded Settings: Randomize =" << _randomize << ", Volume =" << volume << ", Width =" << sizex <<
", Height =" << sizey << ", Playlist =" << songList.count() << " items.";
delete configData;
}
void VorbitalDlg::SaveSettings()
{
qDebug() << "SaveSettings.";
QSettings* configData = new QSettings("Zeta Centauri", "Vorbital Player");
configData->setValue("randomize", _randomize);
configData->setValue("volume", _volumeSlider->value());
QSize wsize = size();
configData->setValue("sizex", wsize.width());
configData->setValue("sizey", wsize.height());
QString playlistItems;
for( int i = 0; i < _lstPlaylist->count(); i++ )
{
QListWidgetItem* item = _lstPlaylist->item(i);
QVariant variant = item->data(Qt::UserRole);
QString filename = variant.toString();
qDebug() << "Saving Playlist Item: " << filename << "'.";
if( i > 0 )
{
playlistItems += ";";
}
playlistItems += filename;
}
configData->setValue("playlist", playlistItems);
configData->sync();
qDebug() << "Saved Settings: Randomize =" << _randomize << ", Volume =" << _volumeSlider->value() <<
", Width =" << wsize.width() << ", Height =" << wsize.height() << ", Playlist =" << _lstPlaylist->count() << " items.";
delete configData;
}
/*!
* Control creation for VorbitalDlg
*/
void VorbitalDlg::CreateControls()
{
qDebug() << "CreateControls.";
setAcceptDrops(true);
QVBoxLayout* rootLayout = new QVBoxLayout();
setLayout(rootLayout);
QHBoxLayout* firstRowLayout = new QHBoxLayout();
rootLayout->addLayout(firstRowLayout);
firstRowLayout->setContentsMargins(QMargins(0,0,0,0));
firstRowLayout->setSpacing(2);
_btnBrowse = new QPushButton( this );
_btnBrowse->setIcon(QPixmap(add_xpm));
_btnBrowse->setToolTip("Add file to playlist.");
connect(_btnBrowse, SIGNAL(released()), this, SLOT(OnButtonBrowseClick()));
firstRowLayout->addWidget(_btnBrowse);
_btnBrowseFolder = new QPushButton( this );
_btnBrowseFolder->setIcon(QPixmap(folder_xpm));
_btnBrowseFolder->setToolTip("Add folder to playlist.");
connect(_btnBrowseFolder, SIGNAL(released()), this, SLOT(OnButtonBrowseFolderClick()));
firstRowLayout->addWidget(_btnBrowseFolder);
_btnRemove = new QPushButton( this );
_btnRemove->setIcon(QPixmap(remove_xpm));
_btnRemove->setToolTip("Remove selected item from playlist.");
connect(_btnRemove, SIGNAL(released()), this, SLOT(OnButtonRemoveClick()));
firstRowLayout->addWidget(_btnRemove);
_btnClear = new QPushButton( this );
_btnClear->setIcon(QPixmap(null_xpm));
_btnClear->setToolTip("Clear playlist.");
connect(_btnClear, SIGNAL(released()), this, SLOT(OnButtonClearClick()));
firstRowLayout->addWidget(_btnClear);
_btnReverse = new QPushButton( this );
_btnReverse->setIcon(QPixmap(reverse_xpm));
_btnReverse->setToolTip("Previous track.");
connect(_btnReverse, SIGNAL(released()), this, SLOT(OnButtonReverseClick()));
firstRowLayout->addWidget(_btnReverse);
_btnPause = new QPushButton( this );
_btnPause->setIcon(QPixmap(pause_xpm));
_btnPause->setToolTip("Pause.");
connect(_btnPause, SIGNAL(released()), this, SLOT(OnButtonPauseClick()));
firstRowLayout->addWidget(_btnPause);
_btnStop = new QPushButton( this );
_btnStop->setIcon(QPixmap(stop_xpm));
_btnStop->setToolTip("Stop.");
connect(_btnStop, SIGNAL(released()), this, SLOT(OnButtonStopClick()));
firstRowLayout->addWidget(_btnStop);
_btnPlay = new QPushButton( this );
_btnPlay->setIcon(QPixmap(play_xpm));
_btnPlay->setToolTip("Play.");
connect(_btnPlay, SIGNAL(released()), this, SLOT(OnButtonPlayClick()));
firstRowLayout->addWidget(_btnPlay);
_btnForward = new QPushButton( this );
_btnForward->setIcon(QPixmap(forward_xpm));
_btnForward->setToolTip("Next track.");
connect(_btnForward, SIGNAL(released()), this, SLOT(OnButtonForwardClick()));
firstRowLayout->addWidget(_btnForward);
_btnRandomize = new QPushButton( this );
_btnRandomize->setIcon(QPixmap(normal_xpm));
_btnRandomize->setToolTip("Turn shuffle on or off.");
connect(_btnRandomize, SIGNAL(released()), this, SLOT(OnButtonRandomizeClick()));
firstRowLayout->addWidget(_btnRandomize);
_btnAbout = new QPushButton( this );
_btnAbout->setIcon(QPixmap(question_xpm));
_btnAbout->setToolTip("About Vorbital Player.");
connect(_btnAbout, SIGNAL(released()), this, SLOT(OnAbout()));
firstRowLayout->addWidget(_btnAbout);
QHBoxLayout* secondRowLayout = new QHBoxLayout();
rootLayout->addLayout(secondRowLayout);
secondRowLayout->insertSpacing(6, 6);
QLabel* itemStaticText16 = new QLabel(this);
itemStaticText16->setText("SR:");
itemStaticText16->setToolTip("Sample rate.");
secondRowLayout->addWidget(itemStaticText16);
_txtSampleRate = new QLabel(this);
_txtSampleRate->setText("0");
secondRowLayout->addWidget(_txtSampleRate);
secondRowLayout->insertSpacing(4, 4);
QLabel* itemStaticText20 = new QLabel(this);
itemStaticText20->setText("BR:");
itemStaticText20->setToolTip("Bit rate.");
secondRowLayout->addWidget(itemStaticText20);
_txtBitRate = new QLabel(this);
_txtBitRate->setText("0");
secondRowLayout->addWidget(_txtBitRate);
secondRowLayout->insertSpacing(4, 4);
_txtChannels = new QLabel(this);
_txtChannels->setText("Stereo");
secondRowLayout->addWidget(_txtChannels);
secondRowLayout->insertSpacing(10, 10);
_volumeSlider = new QSlider(Qt::Horizontal, this);
_volumeSlider->setMinimum(0);
_volumeSlider->setMaximum(100);
_volumeSlider->setValue(100);
_volumeSlider->setMaximumSize(100, 24);
connect(_volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(OnVolume(int)));
secondRowLayout->addWidget(_volumeSlider);
secondRowLayout->insertSpacing(10, 10);
_txtTime = new QLabel(this);
_txtTime->setText("0:00");
secondRowLayout->addWidget(_txtTime);
QBitmap* bitmap = new QBitmap(120, 120);
_albumArt = new QLabel(this);
_albumArt->setPixmap(*bitmap);
rootLayout->addWidget(_albumArt);
_albumArt->setVisible(false);
_lstPlaylist = new QListWidget( this );
rootLayout->addWidget(_lstPlaylist);
connect(_lstPlaylist, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(OnPlaylistDoubleClick(QListWidgetItem*)), Qt::AutoConnection);
connect(this, SIGNAL(bitrateChanged(int)), this, SLOT(OnBitrate(int)), Qt::AutoConnection);
connect(this, SIGNAL(numchannelsChanged(int)), this, SLOT(OnNumChannels(int)), Qt::AutoConnection);
connect(this, SIGNAL(samplerateChanged(int)), this, SLOT(OnSampleRate(int)), Qt::AutoConnection);
connect(this, SIGNAL(timeChanged(int)), this, SLOT(OnTime(int)), Qt::AutoConnection);
}
void VorbitalDlg::OnBitrate(int value)
{
qDebug() << "Bitrate changed to " << value << ".";
_txtBitRate->setText(QString("%1").arg(value));
}
void VorbitalDlg::OnListPosition()
{
//_lstPlaylist->SetSelection(event.GetString());
}
void VorbitalDlg::OnNumChannels(int data)
{
qDebug() << "Number of channels changed to " << data << ".";
if( data == 1 )
{
_txtChannels->setText("Mono");
}
else
{
_txtChannels->setText("Stereo");
}
}
void VorbitalDlg::OnTime(int seconds)
{
QString label;
if( (seconds % 60) > 9 )
{
label = QString("%1:%2").arg(seconds / 60).arg(seconds % 60);
}
else
{
label = QString("%1:0%2").arg(seconds / 60).arg(seconds % 60);
}
_txtTime->setText(label);
}
void VorbitalDlg::OnSampleRate(int data)
{
qDebug() << "Samplerate changed to " << data << ".";
_txtSampleRate->setText(QString("%1").arg(data));
}
/**
* Handles right mouse clicks on the playlist.
*/
// TODO: Reimplement this, and bind it to a right click signal.
// This could be used to show an ID3 tag editor.
void VorbitalDlg::OnRightClick()
{
//int index = _lstPlaylist->itemAt(<< mouse position >>);
//if( index > -1 )
//{
// ShowFileInfo(index);
//}
}
/**
* Shows file details for a playlist item.
*/
void VorbitalDlg::ShowFileInfo(int index)
{
QListWidgetItem* item = _lstPlaylist->item(index);
QVariant variant = item->data(Qt::UserRole);
QString filename = variant.toString();
QMessageBox(QMessageBox::Information, filename, "File Location", QMessageBox::Ok);
}
bool VorbitalDlg::ShowToolTips()
{
return true;
}
void VorbitalDlg::OnButtonBrowseClick()
{
QStringList filenames = QFileDialog::getOpenFileNames( this, "Choose a file", ".",
"Supported Files (*.aif *.aiff *.mp3 *.ogg *.snd *.wav *.wv)" );
for( int i = 0; i < filenames.length(); i++ )
{
QFileInfo info(filenames[i]);
QListWidgetItem* item = new QListWidgetItem(info.baseName());
item->setData(Qt::UserRole, QVariant(info.absoluteFilePath()));
_lstPlaylist->addItem(item);
}
if( _lstPlaylist->currentRow() < 0 )
{
_lstPlaylist->setCurrentRow(0);
_listPosition = 0;
}
}
void VorbitalDlg::OnButtonBrowseFolderClick()
{
QFileDialog fdialog( this, "Choose a directory", ".");
QString dir = QFileDialog::getExistingDirectory(this, "Choose a directory", ".", QFileDialog::ShowDirsOnly);
qDebug() << "Directory: " << dir << ".";
QDir workingDirectory(dir);
QStringList filters;
filters << "*.wav" << "*.mp3" << "*.ogg" << "*.wv" << "*.snd" << "*.aif" << "*.aiff" /*<< "*.flac"*/;
QFileInfoList files = workingDirectory.entryInfoList(filters, QDir::Files, QDir::Name);
for( int i = 0; i < files.count(); i++ )
{
QListWidgetItem* item = new QListWidgetItem(files[i].baseName());
item->setData(Qt::UserRole, QVariant(files[i].absoluteFilePath()));
_lstPlaylist->addItem(item);
}
if( _lstPlaylist->currentRow() < 0 )
{
_lstPlaylist->setCurrentRow(0);
_listPosition = 0;
}
}
void VorbitalDlg::OnButtonStopClick()
{
qDebug() << "Stop clicked.";
qDebug() << "Setting VorbitalDlg play state to STOPPED.";
_playState = STOPPED;
if( _musicStream )
{
_musicStream->Stop();
}
}
void VorbitalDlg::OnButtonPauseClick()
{
qDebug() << "Pause clicked.";
if( _playState == PLAYING )
{
_musicStream->PausePlayback();
}
}
void VorbitalDlg::OnButtonSettingsClick()
{
SettingsDlg* dlg = new SettingsDlg(this);
dlg->setModal(true);
dlg->show();
delete dlg;
}
void VorbitalDlg::OnButtonReverseClick()
{
if( _lstPlaylist->count() < 1 )
{
return;
}
bool playing = false;
if( _musicStream )
{
if( _musicStream->IsPlaying() || _musicStream->IsPaused() )
{
_musicStream->Stop();
playing = true;
}
}
// Set play pointer to next item.
if( !_randomize )
{
--_listPosition;
}
else
{
_listPosition = rand() % _lstPlaylist->count();
}
_incrementNeeded = false;
// Wrap list if necessary.
if( _listPosition < 0 )
{
_listPosition = _lstPlaylist->count() - 1;
}
_lstPlaylist->setCurrentRow( _listPosition );
if( playing == true )
{
OnButtonPlayClick();
}
}
void VorbitalDlg::OnButtonForwardClick()
{
if( _lstPlaylist->count() < 1 )
{
return;
}
bool playing = false;
if( _musicStream )
{
if( _musicStream->IsPlaying() || _musicStream->IsPaused() )
{
_musicStream->Stop();
playing = true;
}
}
// Set play pointer to next item.
if( !_randomize )
{
++_listPosition;
}
else
{
_listPosition = rand() % _lstPlaylist->count();
}
_incrementNeeded = false;
// Wrap list if necessary.
if( _listPosition >= _lstPlaylist->count() )
{
_listPosition = 0;
}
_lstPlaylist->setCurrentRow( _listPosition );
if( playing == true )
{
OnButtonPlayClick();
}
}
void VorbitalDlg::OnButtonRandomizeClick()
{
_randomize = !_randomize;
if( _randomize )
{
_btnRandomize->setIcon( QPixmap(random_xpm) );
}
else
{
_btnRandomize->setIcon( QPixmap(normal_xpm) );
}
}
/*!
* Remove from playlist butto handler.
*/
void VorbitalDlg::OnButtonRemoveClick()
{
// Can't delete from a blank list.
if( _lstPlaylist->count() < 1 )
{
return;
}
int removePosition = _lstPlaylist->currentRow();
// Remove the currently selected item from the playlist, or the first item if nothing is selected.
if( removePosition == -1 && _lstPlaylist->count() > 0 )
{
removePosition = 0;
}
QListWidgetItem* item = _lstPlaylist->takeItem( removePosition );
delete item;
if( _lstPlaylist->count() > 0 )
{
// Decrement the list position if it was at the end.
if( _listPosition >= _lstPlaylist->count() )
{
--_listPosition;
}
if( removePosition >= _lstPlaylist->count() )
{
--removePosition;
}
_lstPlaylist->setCurrentRow( removePosition );
}
}
void VorbitalDlg::OnButtonClearClick()
{
_lstPlaylist->clear();
_listPosition = 0;
qDebug() << "Setting VorbitalDlg play state to STOPPED.";
_playState = STOPPED;
}
void VorbitalDlg::OnPlaylistDoubleClick(QListWidgetItem*)
{
_incrementNeeded = false;
if( _musicStream )
{
_musicStream->Stop();
}
qDebug() << "Setting VorbitalDlg play state to STOPPED.";
_playState = STOPPED;
_listPosition = _lstPlaylist->currentRow();
qDebug() << "Setting playlist position to " << _listPosition << ".";
OnButtonPlayClick();
}
/*!
* Play button handler.
*/
void VorbitalDlg::OnButtonPlayClick()
{
qDebug() << "Play clicked.";
if( !_musicStream )
{
qDebug() << "Creating new MusicStream instance.";
_musicStream = new MusicStream(this);
int volume = _volumeSlider->value();
float actualVol = (float)volume / 100.0f;
if( _musicStream != NULL )
{
_musicStream->SetVolume( actualVol );
}
qDebug() << "Playing new MusicStream instance.";
_musicStream->start();
_musicStream->Play();
}
if( _musicStream->IsPaused() )
{
_musicStream->PausePlayback();
}
else if( !_musicStream->IsPlaying() )
{
_lastTimeUpdate = QDateTime::currentDateTime();
_timeElapsed = 0;
}
qDebug() << "Setting VorbitalDlg play state to PLAYING.";
_playState = PLAYING;
}
/**
* Quit handler.
*/
void VorbitalDlg::OnQuit()
{
SaveSettings();
_done = true;
#ifdef WIN32
Sleep(50);
#else
usleep(50);
#endif
qDebug() << "Closing OpenAL context and device.";
alcMakeContextCurrent(NULL);
alcDestroyContext(_context);
alcCloseDevice(_device);
}
/**
* Shows the about box.
*/
void VorbitalDlg::OnAbout()
{
#ifdef WIN32
QMessageBox::about(this, "Vorbital Player 4.0", "Vorbital Player 4.0\nCopyright 2006-2013 Zeta Centauri.\nDeveloped by Jason Champion.\nThe Vorbital Player is free software and may be distributed freely.\nhttp://vorbitalplayer.com\nVorbital uses the libogg 1.3.0, libvorbis 1.3.3, wavpack 4.60.1, mpg123 1.14.2, and libsndfile 1.0.25 libraries.");
#else
QMessageBox::about(this, "Vorbital Player 4.0", "Vorbital Player 4.0\nCopyright 2006-2013 Zeta Centauri.\nDeveloped by Jason Champion.\nThe Vorbital Player is free software and may be distributed freely.\nhttp://vorbitalplayer.com\nVorbital uses the libogg, libvorbis, wavpack, mpg123, and libsndfile libraries.");
#endif
}
/**
* Drag and drop receiver.
*/
void VorbitalDlg::dropEvent(QDropEvent *event)
{
const QMimeData* mimeData = event->mimeData();
QString filenames = mimeData->text();
if( mimeData->hasUrls() )
{
qDebug() << "MIME data has URLs from drop action.";
QList<QUrl> urlList = mimeData->urls();
for (int i = 0; i < urlList.size() && i < 32; ++i)
{
QFileInfo info(urlList[i].toLocalFile());
QListWidgetItem* item = new QListWidgetItem(info.baseName());
item->setData(Qt::UserRole, QVariant(info.absoluteFilePath()));
qDebug() << "Adding to playlist: " << urlList[i];
_lstPlaylist->addItem(item);
}
}
qDebug() << "Files dropped: " << filenames;
event->acceptProposedAction();
}
void VorbitalDlg::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasFormat("text/plain"))
{
event->acceptProposedAction();
}
}
void VorbitalDlg::LoadFile( QString& filename )
{
int count = _lstPlaylist->count();
if( _lstPlaylist != NULL )
{
QListWidgetItem* item = new QListWidgetItem(ExtractFilename(filename));
item->setData(Qt::UserRole, QVariant(filename));
_lstPlaylist->addItem(item);
_lstPlaylist->setCurrentRow( count );
}
OnButtonPlayClick();
}
void VorbitalDlg::OnVolume(int volume)
{
if( _musicStream )
{
float actualVol = (float)volume / 100.0f;
_musicStream->SetVolume( actualVol );
}
}
/*
* Rips the extension and directory path off of a filename for prettier playlist display.
*/
QString VorbitalDlg::ExtractFilename(const QString& filename)
{
int startPos = filename.lastIndexOf(QChar('\\'));
if( startPos == filename.length() || startPos == -1 )
startPos = 0;
if( startPos != 0 )
startPos += 1;
int endPos = filename.lastIndexOf(QChar('.'));
QString strng = filename.mid(startPos, endPos-startPos);
return strng;
}
void VorbitalDlg::LoadAlbumArt(const QString& filename)
{
#ifdef WIN32
int endPos = filename.lastIndexOf(QChar('\\'));
#else
int endPos = filename.lastIndexOf(QChar('/'));
#endif
QString dirname = filename.mid(0, endPos+1);
QString artFile = QString("%1%2").arg(dirname).arg("Folder.jpg");
qDebug() << "Loading album art file: " << artFile;
QFile file(artFile);
if( file.exists() )
{
QPixmap image;
if( image.load(artFile) )
{
image = image.scaled(QSize(120, 120), Qt::KeepAspectRatio);
_albumArt->setPixmap(image);
_albumArt->setVisible(true);
}
}
else
{
_albumArt->setVisible(false);
}
}
void VorbitalDlg::UpdateTime()
{
QDateTime currTime = QDateTime::currentDateTime();
_timeElapsed += _lastTimeUpdate.secsTo(currTime);
_lastTimeUpdate = currTime;
emit timeChanged(_timeElapsed);
}
void VorbitalDlg::PausedUpdateTime()
{
// Discard the seconds that pass while we are paused.
_lastTimeUpdate = QDateTime::currentDateTime();
}
void VorbitalDlg::ResetTime()
{
_timeElapsed = 0;
_lastTimeUpdate = QDateTime::currentDateTime();
emit timeChanged(_timeElapsed);
}
void VorbitalDlg::UpdateNumChannels(int channels)
{
if( channels == 1 )
{
emit numchannelsChanged(1);
}
else
{
// Pretend that 2 or more channels is stereo. 0 channels will also show as this... if possible.
emit numchannelsChanged(2);
}
}
void VorbitalDlg::UpdateBitrate(int bitrate)
{
emit bitrateChanged(bitrate);
}
void VorbitalDlg::UpdateSampleRate(int samplerate)
{
emit samplerateChanged(samplerate);
}
void VorbitalDlg::closeEvent(QCloseEvent* event)
{
OnQuit();
event->accept();
}