+bool tostr(T& t, const std::string& s) {
+ std::istringstream iss(s);
+ return !(iss >> t).fail();
+}
+
using namespace musik::square;
using std::cout;
using std::cin;
+using musik::core::Indexer;
+using musik::core::IndexerPtr;
+using musik::core::LibraryFactory;
+using musik::core::LibraryPtr;
+using musik::core::TrackFactory;
+using musik::core::TrackPtr;
+
+static boost::mutex outputMutex;
+
+typedef boost::mutex::scoped_lock Lock;
+static Lock lockOutput() {
+ return Lock(outputMutex);
+}
ConsoleUI::ConsoleUI()
: shouldQuit(false)
, audioEventHandler(this)
-, paused(false)
-{
-// this->transport.EventPlaybackStartedOk.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStartedOk);
-// this->transport.EventPlaybackStartedFail.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStartedFail);
+, paused(false) {
-// this->transport.EventPlaybackStoppedOk.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStoppedOk);
-// this->transport.EventPlaybackStoppedFail.connect(&audioEventHandler, &DummyAudioEventHandler::OnPlaybackStoppedFail);
+ musik::debug::string_logged.connect(this, &ConsoleUI::OnDebug);
- // this->transport.EventVolumeChangedOk.connect(&audioEventHandler, &DummyAudioEventHandler::OnVolumeChangedOk);
- // this->transport.EventVolumeChangedFail.connect(&audioEventHandler, &DummyAudioEventHandler::OnVolumeChangedFail);
+// this->transport.EventPlaybackStopped.connect(&audioEventHandler, &TransportEvents::OnPlaybackStopped);
+// this->transport.EventVolumeChanged.connect(&audioEventHandler, &TransportEvents::OnVolumeChanged);
+// this->transport.EventMixpointReached.connect(&audioEventHandler, &TransportEvents::OnMixpointReached);
+ this->transport.PlaybackStarted.connect(&this->audioEventHandler, &TransportEvents::OnPlaybackStartedOk);
+ this->transport.PlaybackAlmostDone.connect(&this->audioEventHandler, &TransportEvents::OnPlaybackAlmostEnded);
+ this->transport.PlaybackEnded.connect(&this->audioEventHandler, &TransportEvents::OnPlaybackStoppedOk);
+ this->transport.PlaybackError.connect(&this->audioEventHandler, &TransportEvents::OnPlaybackStoppedFail);
+ this->transport.PlaybackPause.connect(&this->audioEventHandler, &TransportEvents::OnPlaybackPaused);
+ this->transport.PlaybackResume.connect(&this->audioEventHandler, &TransportEvents::OnPlaybackResumed);
- // this->transport.EventMixpointReached.connect(&audioEventHandler, &DummyAudioEventHandler::OnMixpointReached);
-
- this->transport.PlaybackStarted.connect(&this->audioEventHandler, &DummyAudioEventHandler::OnPlaybackStartedOk);
- this->transport.PlaybackAlmostDone.connect(&this->audioEventHandler, &DummyAudioEventHandler::OnPlaybackAlmostEnded);
- this->transport.PlaybackEnded.connect(&this->audioEventHandler, &DummyAudioEventHandler::OnPlaybackStoppedOk);
- this->transport.PlaybackError.connect(&this->audioEventHandler, &DummyAudioEventHandler::OnPlaybackStoppedFail);
+}
+
+void ConsoleUI::OnDebug(musik::debug::log_level level, std::string tag, std::string message) {
+ std::cout << " [" << tag << "] " << message << "\n";
}
ConsoleUI::~ConsoleUI() {
}
-void ConsoleUI::Print(std::string s)
-{
- boost::mutex::scoped_lock lock(mutex);
-
- cout << "\n*******************************\n\n";
- cout << s;
- cout << "\n*******************************\n" << std::endl;
-}
-
-void ConsoleUI::Run()
-{
- std::string command;
+void ConsoleUI::Run() {
+ std::string cmd;
transport.SetVolume(0.1);
-
- using musik::core::Indexer;
- using musik::core::IndexerPtr;
- using musik::core::LibraryFactory;
- using musik::core::LibraryPtr;
- using musik::core::TrackFactory;
- using musik::core::TrackPtr;
LibraryPtr library = LibraryFactory::Libraries().at(0); /* there's always at least 1... */
library->Indexer()->AddPath("E:/music/");
- library->Indexer()->RestartSync();
+
+ this->Help();
while (!this->shouldQuit) {
- this->PrintCommands();
- cout << "Enter command: ";
- std::getline(cin, command); // Need getline to handle spaces!
- this->ProcessCommand(command);
+ cout << "> ";
+ std::getline(cin, cmd);
+ this->Process(cmd);
}
}
-void ConsoleUI::PrintCommands()
-{
- boost::mutex::scoped_lock lock(mutex);
+void ConsoleUI::Help() {
+ Lock lock = lockOutput();
- cout << "Commands:\n";
- cout << "\tp [file]: play file (enter full path)\n";
- cout << "\ts: stop playing\n";
- cout << "\tl: list currently playing\n";
- cout << "\tlp: list loaded plugins\n";
- cout << "\tv : set volume to p%\n";
- cout << "\tq: quit";
- cout << std::endl;
+ cout << "help:\n";
+ cout << " pl [file]: play file at path\n";
+ cout << " pa: toggle pause/resume";
+ cout << " st: stop playing\n";
+ cout << " ls: list currently playing\n";
+ cout << " lp: list loaded plugins\n";
+ cout << " v: <0.0-1.0>: set volume to p%\n";
+ cout << " sk : seek to into track\n";
+ cout << " rescan: rescan/index music directories\n";
+ cout << "\n q: quit\n\n";
}
-void ConsoleUI::ProcessCommand(std::string commandString)
+void ConsoleUI::Process(const std::string& cmd)
{
Args args;
- boost::algorithm::split(args, commandString, boost::is_any_of(" "));
+ boost::algorithm::split(args, cmd, boost::is_any_of(" "));
std::string command = args.size() > 0 ? args[0] : "";
args.erase(args.begin());
- if (command == "p")
- {
+ if (command == "rmdir") {
+
+ }
+ else if (command == "addir") {
+
+ }
+ else if (command == "dirs") {
+
+ }
+ else if (command == "rescan" || command == "scan" || command == "index") {
+ LibraryPtr library = LibraryFactory::Libraries().at(0); /* there's always at least 1... */
+ library->Indexer()->RestartSync();
+ }
+ else if (command == "h" || command == "help") {
+ this->Help();
+ }
+ else if (command == "p" || command == "pl") {
this->PlayFile(args);
}
- else if (command == "pa")
- {
+ else if (command == "pa") {
this->Pause();
}
- else if (command == "s")
- {
+ else if (command == "s") {
this->Stop(args);
}
- else if (command == "seek")
- {
- this->SetPosition(args);
+ else if (command == "sk" || command == "seek") {
+ this->SetPosition(args);
}
- else if (command == "l")
- {
+ else if (command == "np" || command == "pl") {
this->ListPlaying();
}
- else if (command == "lp")
- {
+ else if (command == "plugins") {
this->ListPlugins();
}
- else if (command == "v")
- {
+ else if (command == "v" || command == "volume") {
this->SetVolume(args);
}
- else if (command == "q")
- {
+ else if (command == "q" || command == "quit" || command == "exit") {
this->Quit();
}
- else
- {
- cout << "Unknown command\n";
+ else {
+ cout << "\n\nunknown command ('h' for help)\n\n";
}
}
-void ConsoleUI::PlayFile(Args args)
-{
+void ConsoleUI::PlayFile(Args args) {
std::string filename;
- if (args.size() > 0)
- {
+ if (args.size() > 0) {
filename = args[0];
}
int repeat = 1;
- if (args.size() > 1)
- {
- convertString(repeat, args[1]);
+ if (args.size() > 1) {
+ tostr(repeat, args[1]);
}
unsigned int delay = 0;
- if (args.size() > 2)
- {
- if (!convertString(delay, args[2]))
- {
+ if (args.size() > 2) {
+ if (!tostr(delay, args[2])) {
delay = 0;
}
}
- for (int i = 0; i < repeat; ++i)
- {
+ for (int i = 0; i < repeat; ++i) {
transport.Start(filename.c_str()); //TODO: fix to use TrackPtr
- if (delay)
- {
+ if (delay) {
#ifdef WIN32
- Sleep(delay);
+ Sleep(delay);
#else
sleep(delay);
#endif
@@ -208,111 +214,91 @@ void ConsoleUI::PlayFile(Args args)
}
}
-void ConsoleUI::Pause()
-{
- if (this->paused) {
- transport.Resume();
- this->paused = !this->paused;
- }
- else
- {
- transport.Pause();
- this->paused = !this->paused;
- }
+void ConsoleUI::Pause() {
+ if (this->paused) {
+ transport.Resume();
+ this->paused = !this->paused;
+ }
+ else {
+ transport.Pause();
+ this->paused = !this->paused;
+ }
}
-void ConsoleUI::Stop(Args args)
-{
+void ConsoleUI::Stop(Args args) {
this->Stop();
}
-void ConsoleUI::Stop()
-{
+void ConsoleUI::Stop() {
transport.Stop();
}
-void ConsoleUI::ListPlaying()
-{
- /*
- AudioStreamOverview overview = transport.StreamsOverview();
- AudioStreamOverviewIterator it;
-
-
- for (it = overview.begin(); it != overview.end(); ++it)
- {
- cout << *it << '\n';
- }
+void ConsoleUI::ListPlaying() {
+ /*
+ AudioStreamOverview overview = transport.StreamsOverview();
+ AudioStreamOverviewIterator it;
- cout << "------------------\n";
- cout << transport.NumOfStreams() << " playing" << std::std::endl;*/
+
+ for (it = overview.begin(); it != overview.end(); ++it) {
+ cout << *it << '\n';
+ }
+
+ cout << "------------------\n";
+ cout << transport.NumOfStreams() << " playing" << std::std::endl;*/
}
-void ConsoleUI::ListPlugins()
-{
+void ConsoleUI::ListPlugins() {
using musik::core::IPlugin;
using musik::core::PluginFactory;
typedef std::vector > PluginList;
typedef PluginFactory::NullDeleter Deleter;
- PluginList plugins =
- PluginFactory::Instance().QueryInterface("GetPlugin");
+ PluginList plugins = PluginFactory::Instance()
+ .QueryInterface("GetPlugin");
PluginList::iterator it = plugins.begin();
- for ( ; it != plugins.end(); it++)
- {
- cout << (*it)->Name() << '\t' << (*it)->Version() << '\t' << (*it)->Author() << '\n';
+ for ( ; it != plugins.end(); it++) {
+ cout << (*it)->Name() << '\t' <<
+ (*it)->Version() << '\t' <<
+ (*it)->Author() << '\n';
}
}
-void ConsoleUI::SetPosition(Args args)
-{
- if (args.size() > 0) {
- double newPosition = 0;
- if (convertString(newPosition, args[0])) {
- transport.SetPosition(newPosition);
- }
- }
+void ConsoleUI::SetPosition(Args args) {
+ if (args.size() > 0) {
+ double newPosition = 0;
+ if (tostr(newPosition, args[0])) {
+ transport.SetPosition(newPosition);
+ }
+ }
}
-void ConsoleUI::SetVolume(Args args)
-{
- if (args.size() > 0)
- {
+void ConsoleUI::SetVolume(Args args) {
+ if (args.size() > 0) {
float newVolume = 0;
- if (convertString(newVolume, args[0]))
- {
+ if (tostr(newVolume, args[0])) {
this->SetVolume(newVolume);
}
}
}
-void ConsoleUI::SetVolume(float volume)
-{
+void ConsoleUI::SetVolume(float volume) {
transport.SetVolume(volume);
}
-void ConsoleUI::Quit()
-{
+void ConsoleUI::Quit() {
this->shouldQuit = true;
}
-void ConsoleUI::ShutDown()
-{
+void ConsoleUI::ShutDown() {
}
#ifdef WIN32
-/*static*/ DWORD WINAPI ConsoleUI::ThreadRun(LPVOID param)
-{
- ConsoleUI* instance = (ConsoleUI*)param;
+/*static*/ DWORD WINAPI ConsoleUI::ThreadRun(LPVOID param) {
+ ConsoleUI* instance = (ConsoleUI*) param;
instance->Run();
delete instance;
return 0;
}
#endif
-
-void ConsoleUI::StartNew()
-{
- Args a;
- this->PlayFile(a);
-}
diff --git a/src/square/ConsoleUI.h b/src/square/ConsoleUI.h
index 65f2ad10c..498d97fff 100644
--- a/src/square/ConsoleUI.h
+++ b/src/square/ConsoleUI.h
@@ -38,12 +38,10 @@
#include "stdafx.h"
#include
-
#include
-
+#include
#include
-
-#include "DummyAudioEventHandler.h"
+#include "TransportEvents.h"
using namespace musik::core::audio;
@@ -51,55 +49,45 @@ class AudioStream;
namespace musik { namespace square {
-typedef std::vector Args;
+ typedef std::vector Args;
-class ConsoleUI
-{
-public: ConsoleUI();
-public: ~ConsoleUI();
+ class ConsoleUI : public sigslot::has_slots<> {
+ public:
+ ConsoleUI();
+ ~ConsoleUI();
-public: void Run();
-private: void PrintCommands();
-private: void ProcessCommand(std::string commandString);
-public: void Print(std::string s);
+ void Run();
-// Commands
-private: void PlayFile(Args args);
-private: void Pause();
-private: void Stop(Args args);
-private: void Stop();
-private: void ListPlaying();
-private: void ListPlugins();
-private: void SetPosition(Args args);
-private: void SetVolume(Args args);
-private: void SetVolume(float volume);
-private: void Quit();
+ private:
+ void Help();
+ void Process(const std::string& cmd);
-// Members
-private: bool shouldQuit;
-private: bool paused;
-private: Transport transport;
-private: DummyAudioEventHandler audioEventHandler;
+ void PlayFile(Args args);
+ void Pause();
+ void Stop(Args args);
+ void Stop();
+ void ListPlaying();
+ void ListPlugins();
+ void SetPosition(Args args);
+ void SetVolume(Args args);
+ void SetVolume(float volume);
+ void Quit();
-private: boost::mutex mutex;
+ void OnDebug(musik::debug::log_level level, std::string tag, std::string message);
-private: void ShutDown();
+ bool shouldQuit;
+ bool paused;
+ Transport transport;
+ TransportEvents audioEventHandler;
-#ifdef WIN32
-public: static DWORD WINAPI ThreadRun(LPVOID param);
-#endif
+ boost::mutex mutex;
-public: void StartNew();
-};
+ void ShutDown();
+
+ #ifdef WIN32
+ public: static DWORD WINAPI ThreadRun(LPVOID param);
+ #endif
+
+ };
}} // NS
-
-// TODO: move to utility file
-#include
-
-template
-bool convertString(T& t, const std::string& s)
-{
- std::istringstream iss(s);
- return !(iss >> t).fail();
-}
diff --git a/src/square/DummyAudioEventHandler.cpp b/src/square/TransportEvents.cpp
similarity index 79%
rename from src/square/DummyAudioEventHandler.cpp
rename to src/square/TransportEvents.cpp
index 3716a4a80..3683b7010 100644
--- a/src/square/DummyAudioEventHandler.cpp
+++ b/src/square/TransportEvents.cpp
@@ -32,29 +32,18 @@
//////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
-
-#include "DummyAudioEventHandler.h"
-
+#include "TransportEvents.h"
#include "ConsoleUI.h"
using namespace musik::square;
-DummyAudioEventHandler::DummyAudioEventHandler(ConsoleUI* c)
-: cui(c)
-{
+TransportEvents::TransportEvents(ConsoleUI* c)
+: cui(c) {
}
-DummyAudioEventHandler::~DummyAudioEventHandler()
-{
+TransportEvents::~TransportEvents() {
}
-void DummyAudioEventHandler::PrintEvent(std::string s)
-{
- this->cui->Print("EVENT: " + s + "\n");
-}
-
-void DummyAudioEventHandler::OnMixpointReached()
-{
- this->PrintEvent("Mix point reached");
- //this->cui->StartNew(); // Endless test loop
-}
+void TransportEvents::LogEvent(std::string s) {
+ musik::debug::log("playback", s);
+}
\ No newline at end of file
diff --git a/src/square/DummyAudioEventHandler.h b/src/square/TransportEvents.h
similarity index 55%
rename from src/square/DummyAudioEventHandler.h
rename to src/square/TransportEvents.h
index 8c6770110..b02118620 100644
--- a/src/square/DummyAudioEventHandler.h
+++ b/src/square/TransportEvents.h
@@ -34,41 +34,37 @@
#pragma once
#include "stdafx.h"
-
#include "config.h"
-
#include
-
#include
namespace musik { namespace square {
-class ConsoleUI;
+ class ConsoleUI;
-//enum AudioStreamEvent;
+ class TransportEvents : public sigslot::has_slots<> {
+ public:
+ TransportEvents(ConsoleUI* c);
+ ~TransportEvents();
-class DummyAudioEventHandler : public sigslot::has_slots<>
-{
-public: DummyAudioEventHandler(ConsoleUI* c);
-public: ~DummyAudioEventHandler();
+ void OnPlaybackAlmostEnded() { this->LogEvent("about to end"); };
+ void OnPlaybackStartedOk() { this->LogEvent("started"); };
+ void OnPlaybackStartedFail() { this->LogEvent("failed"); };
+ void OnPlaybackStoppedOk() { this->LogEvent("stopped"); };
+ void OnPlaybackStoppedFail() { this->LogEvent("stopped because of failure"); };
+ void OnPlaybackInterrupted() { this->LogEvent("interrupted (??)"); };
+ void OnVolumeChangedOk() { this->LogEvent("volume changed"); };
+ void OnStreamOpenOk() { this->LogEvent("stream open ok"); };
+ void OnStreamOpenFail() { this->LogEvent("stream open fail"); };
+ void OnMixpointReached() { this->LogEvent("mix point reached"); }
+ void OnSetPositionOk() { this->LogEvent("set position"); };
+ void OnSetPositionFail() { this->LogEvent("set position failed"); };
+ void OnPlaybackPaused() { this->LogEvent("paused"); };
+ void OnPlaybackResumed() { this->LogEvent("resumed"); };
-private: ConsoleUI* cui; // TODO: should probably be interface
-private: void PrintEvent(std::string s);
+ private:
+ ConsoleUI* cui;
+ void LogEvent(std::string s);
+ };
-// Slots
-public: void OnPlaybackAlmostEnded() { this->PrintEvent("Playback almost done"); };
-public: void OnPlaybackStartedOk() { this->PrintEvent("Playback started OK"); };
-public: void OnPlaybackStartedFail() { this->PrintEvent("Playback started FAIL"); };
-public: void OnPlaybackStoppedOk() { this->PrintEvent("Playback stopped OK"); };
-public: void OnPlaybackStoppedFail() { this->PrintEvent("Playback stopped FAIL"); };
-public: void OnPlaybackInterrupted() { this->PrintEvent("Playback interrupted"); };
-public: void OnVolumeChangedOk() { this->PrintEvent("Volume changed OK"); };
-public: void OnVolumeChangedFail() { this->PrintEvent("Volume changed FAIL"); };
-public: void OnStreamOpenOk() { this->PrintEvent("Stream open OK"); };
-public: void OnStreamOpenFail() { this->PrintEvent("Stream open FAIL"); };
-public: void OnMixpointReached() ;
-public: void OnSetPositionOk() { this->PrintEvent("Set position OK"); };
-public: void OnSetPositionFail() { this->PrintEvent("Set position FAIL"); };
-};
-
-}} // NS
+} }
diff --git a/src/square/player.cpp b/src/square/player.cpp
index 0dbc8a155..f6bb4b4f8 100644
--- a/src/square/player.cpp
+++ b/src/square/player.cpp
@@ -49,14 +49,17 @@ int main(int argc, char* argv[])
#endif
{
/* the following allows boost::filesystem to use utf8 on Windows */
- //std::locale::global(boost::locale::generator().generate(""));
std::locale locale = std::locale();
std::locale utf8Locale(locale, new boost::filesystem::detail::utf8_codecvt_facet);
boost::filesystem::path::imbue(utf8Locale);
+ musik::debug::init();
+
ConsoleUI* instance = new ConsoleUI();
instance->Run();
delete instance;
- return 0;
+ musik::debug::deinit();
+
+ return 0;
}
diff --git a/src/square/player.vcxproj b/src/square/player.vcxproj
index 77e3b1cc2..e85fda41c 100755
--- a/src/square/player.vcxproj
+++ b/src/square/player.vcxproj
@@ -111,7 +111,7 @@