commit 7b18341187c6f24b6fe80dabb2ca4e1065a3461a
parent be986d971f2178005ae7b83a250b2edcc6a1c0c7
Author: fundamental <mark.d.mccurry@gmail.com>
Date: Tue, 29 Dec 2009 13:45:05 -0500
Nio: Work on input interface
- Created Engine Manager to hold inputs and outputs
- Created Engine abstract base class
- Moved Initialization code from OutMgr to EngineMgr
- Added Welcome message
Diffstat:
9 files changed, 179 insertions(+), 78 deletions(-)
diff --git a/src/Nio/AudioOut.h b/src/Nio/AudioOut.h
@@ -27,8 +27,9 @@
#include <pthread.h>
#include "OutMgr.h"
#include "../Misc/Atomic.h"
+#include "Engine.h"
-class AudioOut
+class AudioOut : public virtual Engine
{
public:
AudioOut(OutMgr *out);
diff --git a/src/Nio/CMakeLists.txt b/src/Nio/CMakeLists.txt
@@ -9,6 +9,8 @@ set(zynaddsubfx_nio_SRCS
AudioOut.cpp
OutMgr.cpp
InMgr.cpp
+ Engine.cpp
+ EngineMgr.cpp
MidiEvent.cpp
)
diff --git a/src/Nio/Engine.cpp b/src/Nio/Engine.cpp
@@ -0,0 +1,7 @@
+#include "Engine.h"
+
+Engine::Engine()
+{};
+
+Engine::~Engine()
+{};
diff --git a/src/Nio/Engine.h b/src/Nio/Engine.h
@@ -0,0 +1,10 @@
+#ifndef ENGINE_H
+#define ENGINE_H
+/**Marker for input/output driver*/
+class Engine
+{
+ public:
+ Engine();
+ virtual ~Engine();
+};
+#endif
diff --git a/src/Nio/EngineMgr.cpp b/src/Nio/EngineMgr.cpp
@@ -0,0 +1,80 @@
+#include "EngineMgr.h"
+#include <algorithm>
+#include <iostream>
+#include "AudioOut.h"
+#include "NulEngine.h"
+#if OSS
+#include "OssEngine.h"
+#endif
+#if ALSA
+#include "AlsaEngine.h"
+#endif
+#if JACK
+#include "JackEngine.h"
+#endif
+#if PORTAUDIO
+#include "PaEngine.h"
+#endif
+
+using namespace std;
+
+EngineMgr *sysEngine;
+
+EngineMgr::EngineMgr()
+{
+ //conditional compiling mess (but contained)
+ engines["NULL"] = defaultEng = new NulEngine(sysOut);
+#if OSS
+#if OSS_DEFAULT
+ engines["OSS"] = defaultEng = new OssEngine(sysOut);
+#else
+ engines["OSS"] = new OssEngine(sysOut);
+#endif
+#endif
+#if ALSA
+#if ALSA_DEFAULT
+ engines["ALSA"] = defaultEng = new AlsaEngine(sysOut);
+#else
+ engines["ALSA"] = new AlsaEngine(sysOut);
+#endif
+#endif
+#if JACK
+#if JACK_DEFAULT
+ engines["JACK"] = defaultEng = new JackEngine(sysOut);
+#else
+ engines["JACK"] = new JackEngine(sysOut);
+#endif
+#endif
+#if PORTAUDIO
+#if PORTAUDIO_DEFAULT
+ engines["PA"] = defaultEng = new PaEngine(sysOut);
+#else
+ engines["PA"] = new PaEngine(sysOut);
+#endif
+#endif
+
+};
+
+EngineMgr::~EngineMgr()
+{
+ for(map<string, Engine*>::iterator itr = engines.begin();
+ itr != engines.end(); ++itr) {
+ delete itr->second;
+ }
+}
+
+Engine *EngineMgr::getEng(string name)
+{
+ Engine *ans = NULL;
+
+ transform(name.begin(), name.end(), name.begin(), ::toupper);
+ for(map<string, Engine*>::iterator itr = engines.begin();
+ itr != engines.end(); ++itr) {
+ if(itr->first == name) {
+ ans = itr->second;
+ break;
+ }
+ }
+ return ans;
+}
+
diff --git a/src/Nio/EngineMgr.h b/src/Nio/EngineMgr.h
@@ -0,0 +1,36 @@
+#ifndef ENGINE_MGR_H
+#define ENGINE_MGR_H
+
+#include <map>
+#include <string>
+#include "Engine.h"
+
+
+class MidiIn;
+class AudioOut;
+class OutMgr;
+/**Container/Owner of the long lived Engines*/
+class EngineMgr
+{
+ public:
+ EngineMgr();
+ ~EngineMgr();
+
+ /**Gets requested engine
+ * @param name case unsensitive name of engine
+ * @return pointer to Engine or NULL
+ */
+ Engine *getEng(std::string name);
+
+ private:
+ std::map<std::string,Engine *> engines;
+
+ Engine *defaultEng;/**<The default output*/
+
+ //Engine Manager user
+ friend class OutMgr;
+};
+
+extern EngineMgr *sysEngine;
+#endif
+
diff --git a/src/Nio/MidiIn.h b/src/Nio/MidiIn.h
@@ -23,8 +23,10 @@
#ifndef MIDI_IN_H
#define MIDI_IN_H
+#include "Engine.h"
+
/**This class is inherited by all the Midi input classes*/
-class MidiIn
+class MidiIn : public virtual Engine
{
public:
static int getcontroller(unsigned char b);
diff --git a/src/Nio/OutMgr.cpp b/src/Nio/OutMgr.cpp
@@ -2,21 +2,10 @@
#include <algorithm>
#include <iostream>
#include "AudioOut.h"
+#include "Engine.h"
+#include "EngineMgr.h"
#include "../Misc/Master.h"
#include "../Misc/Util.h"//for set_realtime()
-#include "NulEngine.h"
-#if OSS
-#include "OssEngine.h"
-#endif
-#if ALSA
-#include "AlsaEngine.h"
-#endif
-#if JACK
-#include "JackEngine.h"
-#endif
-#if PORTAUDIO
-#include "PaEngine.h"
-#endif
using namespace std;
@@ -35,40 +24,6 @@ OutMgr::OutMgr(Master *nmaster)
//init samples
outr = new REALTYPE[SOUND_BUFFER_SIZE];
outl = new REALTYPE[SOUND_BUFFER_SIZE];
-
- //conditional compiling mess (but contained)
- managedOuts["NULL"] = defaultOut = new NulEngine(this);
-#if OSS
-#if OSS_DEFAULT
- managedOuts["OSS"] = defaultOut = new OssEngine(this);
-#else
- managedOuts["OSS"] = new OssEngine(this);
-#endif
-#endif
-#if ALSA
-#if ALSA_DEFAULT
- managedOuts["ALSA"] = defaultOut = new AlsaEngine(this);
-#else
- managedOuts["ALSA"] = new AlsaEngine(this);
-#endif
-#endif
-#if JACK
-#if JACK_DEFAULT
- managedOuts["JACK"] = defaultOut = new JackEngine(this);
-#else
- managedOuts["JACK"] = new JackEngine(this);
-#endif
-#endif
-#if PORTAUDIO
-#if PORTAUDIO_DEFAULT
- managedOuts["PA"] = defaultOut = new PaEngine(this);
-#else
- managedOuts["PA"] = new PaEngine(this);
-#endif
-#endif
- defaultOut->out(Stereo<Sample>(Sample(SOUND_BUFFER_SIZE * 20, 0.0),
- Sample(SOUND_BUFFER_SIZE * 20, 0.0)));
-
};
OutMgr::~OutMgr()
@@ -83,10 +38,7 @@ OutMgr::~OutMgr()
pthread_mutex_unlock(&processing);
pthread_join(outThread, NULL);
- for(map<string,AudioOut*>::iterator itr = managedOuts.begin();
- itr != managedOuts.end(); ++itr) {
- delete itr->second;
- }
+
pthread_mutex_destroy(&mutex);
pthread_mutex_destroy(&processing);
pthread_cond_destroy(&needsProcess);
@@ -99,6 +51,13 @@ void *_outputThread(void *arg)
void *OutMgr::outputThread()
{
+ defaultOut = dynamic_cast<AudioOut *>(sysEngine->defaultEng);
+ if(!defaultOut) {
+ cerr << "ERROR: It looks like someone broke the Nio Output\n"
+ << " Attempting to recover by defaulting to the\n"
+ << " Null Engine." << endl;
+ defaultOut = dynamic_cast<AudioOut *>(sysEngine->getEng("NULL"));
+ }
set_realtime();
//open up the default output
@@ -134,23 +93,21 @@ void *OutMgr::outputThread()
Sample(SOUND_BUFFER_SIZE, outr));
pthread_mutex_lock(&mutex);
- if(false)
- cout << "output to ";
- for(map<string,AudioOut*>::iterator itr = managedOuts.begin();
- itr != managedOuts.end(); ++itr) {
- if(itr->second->isEnabled())
- itr->second->out(smps);
- if(false)
- cout << itr->second << " ";
+
+ for(map<string, Engine*>::iterator itr = sysEngine->engines.begin();
+ itr != sysEngine->engines.end(); ++itr) {
+ AudioOut *out = dynamic_cast<AudioOut *>(itr->second);
+ if(out && out->isEnabled())
+ out->out(smps);
}
+
for(list<AudioOut*>::iterator itr = unmanagedOuts.begin();
itr != unmanagedOuts.end(); ++itr) {
(*itr)->out(smps);
if(false)
cout << *itr << " ";
}
- if(false)
- cout << endl;
+
pthread_mutex_unlock(&mutex);
//wait for next run
@@ -180,17 +137,7 @@ void OutMgr::run()
AudioOut *OutMgr::getOut(string name)
{
- AudioOut *ans = NULL;
-
- transform(name.begin(), name.end(), name.begin(), ::toupper);
- for(map<string,AudioOut*>::iterator itr = managedOuts.begin();
- itr != managedOuts.end(); ++itr) {
- if(itr->first == name) {
- ans = itr->second;
- break;
- }
- }
- return ans;
+ return dynamic_cast<AudioOut *>(sysEngine->getEng(name));
}
void OutMgr::add(AudioOut *driver)
@@ -207,8 +154,10 @@ void OutMgr::remove(AudioOut *out)
pthread_mutex_lock(&mutex);
unmanagedOuts.remove(out);
out->Stop();//tells engine to stop
- out->out(Stereo<Sample>(Sample(SOUND_BUFFER_SIZE),
- Sample(SOUND_BUFFER_SIZE)));//gives a dummy sample to make sure it is not stuck
+
+ //gives a dummy sample to make sure it is not stuck
+ out->out(Stereo<Sample>(Sample(SOUND_BUFFER_SIZE, 0.0),
+ Sample(SOUND_BUFFER_SIZE, 0.0)));
pthread_mutex_unlock(&mutex);
}
diff --git a/src/main.cpp b/src/main.cpp
@@ -39,8 +39,10 @@
#include "Misc/Dump.h"
extern Dump dump;
+//Nio System
#include "Nio/OutMgr.h"
#include "Nio/InMgr.h"
+#include "Nio/EngineMgr.h"
#warning TODO remove conditional include block
#if 0
@@ -222,10 +224,22 @@ void initprogram()
#endif
#endif
- sysOut = new OutMgr(master);
+ //Nio Initialization
+
+ //Enable input wrapper
+ sysIn = new InMgr(master);
+
+ //Initialize the Output Systems
+ sysOut = new OutMgr(master);
+
+ //Initialize The Engines
+ sysEngine = new EngineMgr();
+
+ //Run the system
sysOut->run();
+#warning remove welcome message when system is out of beta
+ cout << "\nThanks for using the Nio system :)" << endl;
- sysIn = new InMgr(master);
#ifndef DISABLE_GUI
ui = new MasterUI(master, &Pexitprogram);