Skip to content

Commit f30940f

Browse files
committed
Merge branch 'feature/Drag_and_drop' into develop
2 parents 8fc92ba + de01436 commit f30940f

10 files changed

+45
-21
lines changed

Build/RH/ResourceHacker.log

-544 Bytes
Binary file not shown.

Installer/ascii_player.exe

1.5 KB
Binary file not shown.
Binary file not shown.

Source/AudioFile.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
namespace ASCIIPlayer
55
{
66
// Static init.
7-
APUnique AudioFile::uniqueID_ = 0; // ID for lookup in the audio system
7+
APUnique AudioFile::uniqueID_STATIC_VAR_ = 0; // ID for lookup in the audio system
88

99

1010
// Constructor and Destructor
1111
AudioFile::AudioFile(std::string path)
1212
: path_(path)
13-
, fileID_(uniqueID_++)
13+
, fileID_(uniqueID_STATIC_VAR_++)
1414
, loadedObjects_() // Assigned via lazy init later
1515
{ }
1616

Source/AudioFile.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ namespace ASCIIPlayer
4040
std::unordered_map<APUnique, AudioHandleWrapper> loadedObjects_; // Handle to the loaded object.
4141

4242
// Static Variables
43-
static APUnique uniqueID_; // ID for lookup in the audio system
43+
static APUnique uniqueID_STATIC_VAR_; // ID for lookup in the audio system
4444
};
4545
}

Source/AudioSystem.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ namespace ASCIIPlayer
143143

144144
// @ToDo: Channel override may result in same song playing multiple times.
145145
// Test this and confirm if it is an issue that needs to be solved.
146-
channelHandles_[audioFile.uniqueID_] = channel;
146+
channelHandles_[audioFile.fileID_] = channel;
147147
audioFile.get(ID_)->BoundToChannel = true;
148148
}
149149

@@ -162,7 +162,7 @@ namespace ASCIIPlayer
162162

163163
// Toggle paused using !
164164
bool pausedStatus;
165-
ChannelHandle ch = channelHandles_[audioFile.uniqueID_];
165+
ChannelHandle ch = channelHandles_[audioFile.fileID_];
166166
FCheck(ch->getPaused(&pausedStatus));
167167

168168
if (pausedState)
@@ -180,7 +180,7 @@ namespace ASCIIPlayer
180180
// Stops the audio file completely, removing the channel.
181181
void AudioSystem::StopFile(AudioFile &audioFile)
182182
{
183-
ChannelHandle *ch = &channelHandles_[audioFile.uniqueID_];
183+
ChannelHandle *ch = &channelHandles_[audioFile.fileID_];
184184
bool playing;
185185
(*ch)->isPlaying(&playing);
186186
if(playing)
@@ -233,14 +233,14 @@ namespace ASCIIPlayer
233233
bool AudioSystem::IsActive(AudioFile &audioFile)
234234
{
235235
bool status;
236-
channelHandles_[audioFile.uniqueID_]->isPlaying(&status);
236+
channelHandles_[audioFile.fileID_]->isPlaying(&status);
237237
return status;
238238
}
239239

240240
bool AudioSystem::IsPaused(AudioFile &audioFile)
241241
{
242242
bool status;
243-
channelHandles_[audioFile.uniqueID_]->getPaused(&status);
243+
channelHandles_[audioFile.fileID_]->getPaused(&status);
244244
return status;
245245
}
246246

@@ -260,7 +260,7 @@ namespace ASCIIPlayer
260260
return 0;
261261

262262
unsigned int tu;
263-
FCheck(channelHandles_[audioFile.uniqueID_]->getPosition(&tu, FMOD_TIMEUNIT_MS));
263+
FCheck(channelHandles_[audioFile.fileID_]->getPosition(&tu, FMOD_TIMEUNIT_MS));
264264
return tu;
265265
}
266266

@@ -275,7 +275,7 @@ namespace ASCIIPlayer
275275
if (length <= pos)
276276
pos = length - 1;
277277

278-
FCheck(channelHandles_[audioFile.uniqueID_]->setPosition(pos, FMOD_TIMEUNIT_MS));
278+
FCheck(channelHandles_[audioFile.fileID_]->setPosition(pos, FMOD_TIMEUNIT_MS));
279279
}
280280

281281

Source/DJ.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace ASCIIPlayer
7575
if (!hasShutdown_)
7676
{
7777
// Update the song and proceed if necessary
78-
if (!audioSystem_.IsActive(*currSong_))
78+
if (currSong_ && !audioSystem_.IsActive(*currSong_))
7979
{
8080
playlist_.Next();
8181

@@ -96,7 +96,7 @@ namespace ASCIIPlayer
9696
}
9797

9898
// Draw overlay after visualizer so it's "On top"
99-
if (overlay_)
99+
if (currSong_ && overlay_)
100100
{
101101
overlay_->Update(
102102
UIInfo(requestUIActive_
@@ -148,6 +148,10 @@ namespace ASCIIPlayer
148148
}
149149
}
150150

151+
bool DJ::IsPaused()
152+
{
153+
return paused_;
154+
}
151155

152156
// Toggles if it's paused or not
153157
void DJ::TogglePause()
@@ -189,8 +193,15 @@ namespace ASCIIPlayer
189193
// The DJ does NOT handle deallocation for you, in case you wanted to add this to other DJs.
190194
void DJ::AddSong(AudioFile *toAdd)
191195
{
196+
bool start = false;
197+
if (playlist_.GetPlaylistLength() == 0)
198+
start = true;
199+
192200
if(audioSystem_.PreloadFile(*toAdd))
193201
playlist_.Add(toAdd);
202+
203+
if (start)
204+
Play();
194205
}
195206

196207

Source/DJ.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace ASCIIPlayer
2222
bool Update();
2323
void Play();
2424
void Pause();
25+
bool IsPaused();
2526
void TogglePause();
2627
void ToggleRequestUIActive();
2728
void Shutdown();
@@ -41,7 +42,7 @@ namespace ASCIIPlayer
4142
private:
4243
// Callback
4344
void playlistUpdatedCallback();
44-
void updateLastVolumeChange();
45+
void updateLastVolumeChange();
4546

4647
// Variables
4748
Playlist<DJ> playlist_; // Contains the AudioFile objects.

Source/Lobby.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,14 @@ namespace ASCIIPlayer
198198

199199
void Lobby::interpretPath(const std::string str)
200200
{
201-
201+
std::string input = str;
202+
if (str[0] == '"' && str[str.size() - 1] == '"')
203+
input = str.substr(1, str.size() - 2);
204+
if (str[0] == '\\' && str[str.size() - 1] == '"')
205+
input = str.substr(2, str.size() - 4);
206+
207+
AudioFile *test1 = new ASCIIPlayer::AudioFile(input);
208+
activeDJ_->AddSong(test1);
202209
}
203210

204211
void Lobby::interpretString(const std::string command)
@@ -410,7 +417,7 @@ namespace ASCIIPlayer
410417
activeDJ_ = newDJ;
411418
}
412419

413-
420+
// Move to the right in the menu
414421
bool Lobby::menuMoveCheckRight()
415422
{
416423
if (menuSystems_.MenuDepth() == 2)
@@ -423,7 +430,7 @@ namespace ASCIIPlayer
423430
return false;
424431
}
425432

426-
433+
// Move to the left in the menu, wrapps the actions assoicated with it
427434
bool Lobby::menuMoveCheckLeft()
428435
{
429436
if (menuSystems_.MenuDepth() == 2)

Source/Playlist.hpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace ASCIIPlayer
3232

3333
// Variables
3434
std::vector<AudioFile*> playlist_; // Holds songs to be played.
35-
unsigned int activeIndex_; // Active index into the playlist.
36-
bool looping_; // Are we looping this playlist?
35+
unsigned int activeIndex_; // Active index into the playlist.
36+
bool looping_; // Are we looping this playlist?
3737

3838
// Callback info.
3939
void(T::*toCallOnUpdate_)();
@@ -58,10 +58,12 @@ namespace ASCIIPlayer
5858
// Adds a new audiofile to a playlist.
5959
template<typename T> void Playlist<T>::Add(AudioFile *file)
6060
{
61+
6162
playlist_.push_back(file);
62-
63-
if(playlist_.size() == 1)
64-
listUpdateCallback();
63+
64+
// Update to the added song and update the list
65+
activeIndex_ = playlist_.size() - 1;
66+
listUpdateCallback();
6567
}
6668

6769

@@ -103,6 +105,9 @@ namespace ASCIIPlayer
103105
// If possible, will attempt to go to the next song.
104106
template<typename T> void Playlist<T>::Next()
105107
{
108+
if (playlist_.size() == 0)
109+
return;
110+
106111
if (activeIndex_ < playlist_.size() - 1)
107112
{
108113
++activeIndex_;

0 commit comments

Comments
 (0)