Skip to content

Commit 65fda2e

Browse files
Merge pull request #2 from corporateshark/playlist
Added playlists
2 parents 4340a6f + 38dfbf5 commit 65fda2e

File tree

7 files changed

+85
-23
lines changed

7 files changed

+85
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Usage:
1717
------
1818

1919
```
20-
portamp <filename> [--loop] [--wav-modplug]
20+
portamp <filename> [<filename2> ...] [--loop] [--wav-modplug] [--verbose]
2121
```
2222

2323
Features:

src/AudioSubsystem_OpenAL.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "AudioSubsystem_OpenAL.h"
1515
#include "Decoders/iWaveDataProvider.h"
1616
#include "OpenAL/LAL.h"
17+
#include "Utils.h"
1718

1819
const int BUFFER_DURATION = 250; // milliseconds
1920
const int BUFFER_SIZE = 44100 * 2 * 2 * BUFFER_DURATION / 1000;
@@ -317,7 +318,7 @@ void clAudioSource_OpenAL::SetLooping( bool Looping )
317318

318319
bool IsStreaming = m_DataProvider && m_DataProvider->IsStreaming();
319320

320-
if ( !IsStreaming )
321+
if ( m_DataProvider && !IsStreaming )
321322
{
322323
alSourcei( m_SourceID, AL_LOOPING, Looping ? AL_TRUE : AL_FALSE );
323324
}
@@ -352,7 +353,7 @@ void clAudioSubsystem_OpenAL::DebugPrintVersion()
352353
printf( "OpenAL version : %s\n", alGetString( AL_VERSION ) );
353354
printf( "OpenAL vendor : %s\n", alGetString( AL_VENDOR ) );
354355
printf( "OpenAL renderer: %s\n", alGetString( AL_RENDERER ) );
355-
printf( "OpenAL extensions:\n%s\n", alGetString( AL_EXTENSIONS ) );
356+
printf( "OpenAL extensions:\n%s\n\n", alGetString( AL_EXTENSIONS ) );
356357
}
357358

358359
void clAudioSubsystem_OpenAL::Start()
@@ -364,7 +365,7 @@ void clAudioSubsystem_OpenAL::Start()
364365
m_Context = alcCreateContext( m_Device, nullptr );
365366
alcMakeContextCurrent( m_Context );
366367

367-
DebugPrintVersion();
368+
if ( IsVerbose() ) DebugPrintVersion();
368369

369370
m_IsInitialized = true;
370371

src/Decoders/WAV/WAVDataProvider.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,16 @@ clWAVDataProvider::clWAVDataProvider( const std::shared_ptr<clBlob>& Data )
7979

8080
// m_DataSize = Data->GetDataSize() - sizeof(sWAVHeader);
8181

82-
printf( "PCM WAVE\n" );
82+
if ( IsVerbose() )
83+
{
84+
printf( "PCM WAVE\n" );
8385

84-
printf( "Channels = %i\n", Header->Channels );
85-
printf( "Samples/S = %i\n", Header->SampleRate );
86-
printf( "Bits/Sample = %i\n", Header->nBitsperSample );
86+
printf( "Channels = %i\n", Header->Channels );
87+
printf( "Samples/S = %i\n", Header->SampleRate );
88+
printf( "Bits/Sample = %i\n", Header->nBitsperSample );
8789

88-
printf( "m_DataSize = %zu\n", m_DataSize );
90+
printf( "m_DataSize = %zu\n\n", m_DataSize );
91+
}
8992

9093
}
9194
}

src/Playlist.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#include <deque>
4+
#include <string>
5+
6+
class clPlaylist
7+
{
8+
public:
9+
virtual ~clPlaylist() {};
10+
11+
virtual void EnqueueTrack( const char* FileName )
12+
{
13+
m_FileNames.emplace_back( FileName );
14+
}
15+
16+
virtual bool IsEmpty() const { return m_FileNames.empty(); }
17+
virtual size_t GetNumTracks() const { return m_FileNames.size(); }
18+
virtual std::string GetAndPopNextTrack( bool Loop )
19+
{
20+
std::string Result = m_FileNames.front();
21+
22+
m_FileNames.pop_front();
23+
24+
// readd to the end of the list
25+
if ( Loop ) m_FileNames.push_back( Result );
26+
27+
return Result;
28+
}
29+
30+
private:
31+
std::deque<std::string> m_FileNames;
32+
};

src/Utils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
std::vector<uint8_t> ReadFileAsVector( const char* FileName )
1818
{
19+
if ( IsVerbose() ) printf( "Opening %s\n\n", FileName );
20+
1921
std::ifstream File( FileName, std::ifstream::binary | std::ios::in );
2022

2123
if ( File.fail() )
@@ -69,6 +71,10 @@ int IsKeyPressed()
6971
#endif
7072
}
7173

74+
bool IsVerbose()
75+
{
76+
return g_Config.m_Verbose;
77+
}
7278

7379
void Log_Error( const char* Format... )
7480
{

src/Utils.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,19 @@ struct sConfig
6565
sConfig()
6666
: m_Loop( false )
6767
, m_UseModPlugToDecodeWAV( false )
68+
, m_Verbose( false )
6869
{}
6970

7071
bool m_Loop;
7172
bool m_UseModPlugToDecodeWAV;
73+
bool m_Verbose;
7274
};
7375

7476
std::shared_ptr<clBlob> ReadFileAsBlob( const char* FileName );
7577

7678
int IsKeyPressed();
79+
bool IsVerbose();
7780

78-
void Log_Error( const char* Format... );
81+
void Log_Error( const char* Format... );
82+
83+
extern sConfig g_Config;

src/main.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
#include "Decoders/iWaveDataProvider.h"
99
#include "Decoders/WAV/WAVDataProvider.h"
1010
#include "Utils.h"
11+
#include "Playlist.h"
1112

12-
const char* PORTAMP_VERSION = "0.99.9";
13+
const char* PORTAMP_VERSION = "1.0.0";
1314

1415
sConfig g_Config;
16+
clPlaylist g_Playlist;
1517

1618
sConfig ReadConfigFromCommandLine( int argc, char* argv[] )
1719
{
@@ -20,7 +22,9 @@ sConfig ReadConfigFromCommandLine( int argc, char* argv[] )
2022
for ( int i = 1; i < argc; i++ )
2123
{
2224
if ( strstr( argv[i], "--loop" ) == argv[i] ) Cfg.m_Loop = true;
23-
if ( strstr( argv[i], "--wav-modplug" ) == argv[i] ) Cfg.m_UseModPlugToDecodeWAV = true;
25+
else if ( strstr( argv[i], "--wav-modplug" ) == argv[i] ) Cfg.m_UseModPlugToDecodeWAV = true;
26+
else if ( strstr( argv[i], "--verbose" ) == argv[i] ) Cfg.m_Verbose = true;
27+
else g_Playlist.EnqueueTrack( argv[i] );
2428
}
2529

2630
return Cfg;
@@ -32,7 +36,7 @@ void PrintBanner()
3236
printf( "Copyright (C) 2015 Sergey Kosarevsky\n" );
3337
printf( "https://github.com/corporateshark/PortAMP\n" );
3438
printf( "\n" );
35-
printf( "portamp <filename> [--loop] [--wav-modplug]\n" );
39+
printf( "portamp <filename1> [<filename2> ...] [--loop] [--wav-modplug] [--verbose]\n" );
3640
printf( "\n" );
3741
}
3842

@@ -46,25 +50,36 @@ int main( int argc, char* argv[] )
4650

4751
g_Config = ReadConfigFromCommandLine( argc, argv );
4852

49-
const char* FileName = ( argc > 1 ) ? argv[1] : "test.ogg";
53+
if ( g_Playlist.IsEmpty() ) g_Playlist.EnqueueTrack( "test.ogg" );
5054

5155
auto AudioSubsystem = CreateAudioSubsystem_OpenAL();
5256

5357
AudioSubsystem->Start();
5458

55-
auto TestBlob = ReadFileAsBlob( FileName );
56-
auto Provider = CreateWaveDataProvider( FileName, TestBlob );
5759
auto Source = AudioSubsystem->CreateAudioSource();
58-
Source->BindDataProvider( Provider );
59-
Source->SetLooping( g_Config.m_Loop );
60-
Source->Play();
60+
// allow seamless looping if there is only one track
61+
if ( g_Playlist.GetNumTracks() == 1 ) Source->SetLooping( g_Config.m_Loop );
6162

62-
while ( Source->IsPlaying() && !IsKeyPressed() )
63+
bool RequestingExit = false;
64+
65+
while ( !g_Playlist.IsEmpty() && !RequestingExit )
6366
{
64-
std::this_thread::sleep_for( std::chrono::milliseconds(10) );
65-
};
67+
auto FileName = g_Playlist.GetAndPopNextTrack( g_Config.m_Loop );
68+
auto DataBlob = ReadFileAsBlob( FileName.c_str() );
69+
auto Provider = CreateWaveDataProvider( FileName.c_str(), DataBlob );
70+
Source->BindDataProvider( Provider );
71+
Source->Play();
72+
73+
while ( Source->IsPlaying() && !RequestingExit )
74+
{
75+
std::this_thread::sleep_for( std::chrono::milliseconds(10) );
76+
77+
if ( IsKeyPressed() ) RequestingExit = true;
78+
};
79+
80+
Source->Stop();
81+
}
6682

67-
Source->Stop();
6883
Source = nullptr;
6984

7085
AudioSubsystem->Stop();

0 commit comments

Comments
 (0)