zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit 6eaa61f5beb86c64c57b3a20b33dd028ed76d9f5
parent ae8af8ba22774bfe03256cd1ff6ff162cba6f07b
Author: fundamental <[email protected]>
Date:   Mon, 14 Dec 2009 21:18:48 -0500

Nio: Integrating Starting UI

- Incorperating UI into the MasterUI.fl
- Refining the OutMgr/AudioOut classes

Diffstat:
Msrc/CMakeLists.txt | 11+++++++++++
Msrc/Nio/AudioOut.cpp | 2+-
Msrc/Nio/AudioOut.h | 20++++++++++++++------
Msrc/Nio/OutMgr.cpp | 67+++++++++++++++++++++++++++++++++++++++++--------------------------
Msrc/Nio/OutMgr.h | 33+++++++++++++++++++--------------
Msrc/UI/CMakeLists.txt | 1+
Msrc/UI/MasterUI.fl | 10+++++++---
Msrc/UI/NioUI.cpp | 48+++++++++++++-----------------------------------
Asrc/UI/NioUI.h | 27+++++++++++++++++++++++++++
Msrc/main.cpp | 10++++------
10 files changed, 138 insertions(+), 91 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt @@ -42,6 +42,7 @@ else () message(STATUS "GUI module defaulting to off") endif() +#depricated block if (OutputModule STREQUAL alsa AND ALSA_FOUND) set(AlsaMidiOutput TRUE) elseif(OutputModule STREQUAL jack AND JACK_FOUND) @@ -54,6 +55,16 @@ else () message(FATAL_ERROR "OutputModule must be either alsa, nio, jack or portaudio") endif() +if(AlsaEnable) + add_definitions(-DALSA=1) +endif(AlsaEnable) +if(JackEnable) + add_definitions(-DJACK=1) +endif(JackEnable) +if(OssEnable) + add_definitions(-DOSS=1) +endif(OssEnable) + ########### Settings dependant code ########### # From here on, the setting variables have been prepared so concentrate # on the actual compiling. diff --git a/src/Nio/AudioOut.cpp b/src/Nio/AudioOut.cpp @@ -26,7 +26,7 @@ using namespace std; #include "AudioOut.h" AudioOut::AudioOut(OutMgr *out) - :manager(out),threadStop(false) + :manager(out),threadStop(false),enabled(false) { cout << out; pthread_mutex_init(&outBuf_mutex, NULL); diff --git a/src/Nio/AudioOut.h b/src/Nio/AudioOut.h @@ -28,23 +28,30 @@ #include "OutMgr.h" #include "../Misc/Atomic.h" -//class AudioOut; class AudioOut { public: AudioOut(OutMgr *out); virtual ~AudioOut() {}; + //depricated virtual bool openAudio()=0; + //depricated + virtual void Close()=0; + + /**Start the Driver*/ virtual bool Start()=0; + /**Stop the Driver*/ virtual void Stop()=0; - virtual void Close()=0; + + /**Give the Driver Samples to process*/ virtual void out(const Stereo<Sample> smps); - //bool prepAudiobuffers(unsigned int buffersize, bool with_interleaved); - //void silenceBuffers(); - //void dimBuffers(); /**Determines if new operator should/can be used*/ - //virtual bool isSingleton() const {return true;}; + virtual bool isEnabled() const {return enabled();}; + + /**Report the state of the engine + * @return 0 for stoped, 1 for running*/ + virtual int state() const {return enabled();}; protected: /**Get the next sample for output.*/ @@ -60,6 +67,7 @@ class AudioOut //thread resources Atomic<bool> threadStop; pthread_t pThread; + Atomic<bool> enabled; }; #endif diff --git a/src/Nio/OutMgr.cpp b/src/Nio/OutMgr.cpp @@ -3,30 +3,35 @@ #include <iostream> #include "AudioOut.h" #include "../Misc/Master.h" +#include "NulEngine.h" using namespace std; OutMgr *sysOut; -//typedef enum -//{ -// JACK_OUTPUT; -// ALSA_OUTPUT; -// OSS_OUTPUT; -// WINDOWS_OUTPUT; -// WAV_OUTPUT; -//} outputDriver; OutMgr::OutMgr(Master *nmaster) :numRequests(0) { running = false; master = nmaster; + //initialize mutex pthread_mutex_init(&mutex, NULL); pthread_mutex_init(&processing, NULL); pthread_cond_init(&needsProcess, NULL); + //init samples outr = new REALTYPE[SOUND_BUFFER_SIZE]; outl = new REALTYPE[SOUND_BUFFER_SIZE]; + + //conditional compiling + managedOuts["NULL"] = defaultOut = new NulEngine(this); +#if OSS + managedOuts["OSS"] = new OssEngine(this); +#endif +#if ALSA + managedOuts["ALSA"] = new ALSAEngine(this); +#endif + }; OutMgr::~OutMgr() @@ -44,27 +49,28 @@ void *_outputThread(void *arg) void *OutMgr::outputThread() { - pthread_mutex_lock(&mutex); - for(list<AudioOut*>::iterator itr = outs.begin(); itr != outs.end(); ++itr) - (*itr)->Start(); - pthread_mutex_unlock(&mutex); + //pthread_mutex_lock(&mutex); + //for(list<AudioOut*>::iterator itr = outs.begin(); itr != outs.end(); ++itr) + // (*itr)->Start(); + //pthread_mutex_unlock(&mutex); + + if(!defaultOut->openAudio())//there should be a better failsafe + cerr << "ERROR: The default Audio Output Failed to Open!" << endl; + defaultOut->Start(); + //setup running=true; init=true; bool doWait=false; int lRequests; - while(running){ - //pthread_mutex_lock(&request_m); - //lRequests=numRequests--; - //pthread_mutex_unlock(&request_m); - + while(running) { --numRequests; pthread_mutex_lock(&mutex); - if(true) - { + if(true) { cout << "Status: "; - cout << outs.size(); + cout << managedOuts.size() << "-"; + cout << unmanagedOuts.size(); cout << " outs, "; cout << doWait; cout << " waits, "; @@ -94,7 +100,14 @@ void *OutMgr::outputThread() pthread_mutex_lock(&mutex); if(false) cout << "output to "; - for(list<AudioOut*>::iterator itr = outs.begin(); itr != outs.end(); ++itr) { + for(map<string,AudioOut*>::iterator itr = managedOuts.begin(); + itr != managedOuts.end(); ++itr) { + itr->second->out(smps); + if(false) + cout << itr->second << " "; + } + for(list<AudioOut*>::iterator itr = unmanagedOuts.begin(); + itr != unmanagedOuts.end(); ++itr) { (*itr)->out(smps); if(false) cout << *itr << " "; @@ -119,11 +132,16 @@ void OutMgr::run() pthread_create(&outThread, &attr, _outputThread, this); } +AudioOut *OutMgr::getOut(string name) +{ + transform(name.begin(), name.end(), name.begin(), ::toupper); + return managedOuts[name]; +} void OutMgr::add(AudioOut *driver) { pthread_mutex_lock(&mutex); - outs.push_back(driver); + unmanagedOuts.push_back(driver); if(running)//hotplug driver->Start(); pthread_mutex_unlock(&mutex); @@ -132,7 +150,7 @@ void OutMgr::add(AudioOut *driver) void OutMgr::remove(AudioOut *out) { pthread_mutex_lock(&mutex); - outs.remove(out); + 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 @@ -154,6 +172,3 @@ int OutMgr::requestSamples() return 0; } -//int OutMgr::enable(outputDriver out); -//int OutMgr::disable(outputDriver out); - diff --git a/src/Nio/OutMgr.h b/src/Nio/OutMgr.h @@ -5,18 +5,11 @@ #include "../Misc/Stereo.h" #include "../Misc/Atomic.h" #include "../Samples/Sample.h" -//#include "../Misc/Master.h" #include <list> +#include <map> +#include <string> #include <pthread.h> -//typedef enum -//{ -// JACK_OUTPUT; -// ALSA_OUTPUT -// OSS_OUTPUT; -// WINDOWS_OUTPUT; -// WAV_OUTPUT; -//} outputDriver; class AudioOut; class Master; @@ -25,29 +18,41 @@ class OutMgr public: OutMgr(Master *nmaster); ~OutMgr(); + /**Adds audio output out. * @return -1 for error 0 otherwise*/ void add(AudioOut *out); /**Removes given audio output engine * @return -1 for error 0 otherwise*/ void remove(AudioOut *out); + /**Request a new set of samples * @return -1 for locking issues 0 for valid request*/ int requestSamples(); + /**Return the number of building samples*/ int getRunning(); - /**Enables one instance of given driver*/ - //int enable(outputDriver out); - /**Disables all instances of given driver*/ - //int disable(outputDriver out); + void run(); + /**Gets requested driver + * @param name case unsensitive name of driver + * @return pointer to Audio Out or NULL + */ + AudioOut *getOut(std::string name); + void *outputThread(); private: bool running; bool init; - std::list<AudioOut *> outs; + //should hold outputs here that exist for the life of the OutMgr + std::map<std::string,AudioOut *> managedOuts; + AudioOut *defaultOut;/**<The default output*/ + + //should hold short lived, externally controlled Outputs (eg WavEngine) + //[needs mutex] + std::list<AudioOut *> unmanagedOuts; mutable pthread_mutex_t mutex; pthread_mutex_t processing; diff --git a/src/UI/CMakeLists.txt b/src/UI/CMakeLists.txt @@ -27,6 +27,7 @@ fltk_wrap_ui(zynaddsubfx_gui ${UI_fl_files}) add_library(zynaddsubfx_gui STATIC ${UI_objs} ${zynaddsubfx_gui_FLTK_UI_SRCS} + NioUI.cpp ) target_link_libraries(zynaddsubfx_gui ${FLTK_LIBRARIES} ${MYFLTK_LIBRARIES}) diff --git a/src/UI/MasterUI.fl b/src/UI/MasterUI.fl @@ -1,5 +1,5 @@ # data file for the Fltk User Interface Designer (fluid) -version 1.0107 +version 1.0300 header_name {.h} code_name {.cc} decl {//Copyright (c) 2002-2009 Nasca Octavian Paul} {} @@ -48,6 +48,9 @@ decl {\#include "SeqUI.h"} {public decl {\#include "PresetsUI.h"} {public } +decl {\#include "NioUI.h"} {public global +} + decl {\#include "../Misc/Master.h"} {public } @@ -427,7 +430,7 @@ if (fl_choice("Exit and leave the unsaved data?","No","Yes",NULL)) { *exitprogram=1; }; \#endif} - xywh {450 306 390 465} type Double labeltype NORMAL_LABEL align 80 hide xclass zynaddsubfx + xywh {450 306 390 465} type Double align 80 hide xclass zynaddsubfx } { Fl_Menu_Bar mastermenu { xywh {-5 0 690 25} @@ -995,7 +998,7 @@ panelwindow->show();} } Fl_Button {} { label N - callback {newiowindow->show();} selected + callback {nioui.show();} selected xywh {270 75 20 25} } } @@ -1827,4 +1830,5 @@ bankui->hide();} {} decl {int swapefftype;} {} decl {char masterwindowlabel[100];} {} decl {Panellistitem *panellistitem[NUM_MIDI_PARTS];} {} + decl {NioUI nioui;} {} } diff --git a/src/UI/NioUI.cpp b/src/UI/NioUI.cpp @@ -1,17 +1,4 @@ -#include <FL/Fl.H> -#include <FL/Fl_Light_Button.H> -#include <FL/Fl_Window.H> -#include <FL/Fl_Pack.H> -#include <FL/Enumerations.H> - -class Pack : public Fl_Pack -{ - public: - Pack(int x, int y, int w, int h); - private: - Fl_Light_Button b1,b2,b3; - static void nioTogglei(Fl_Widget *wid, void *name); -}; +#include "NioUI.h" Pack::Pack(int x, int y, int w, int h) :Fl_Pack(x,y,w,h), @@ -24,26 +11,17 @@ Pack::Pack(int x, int y, int w, int h) b3.selection_color(fl_rgb_color(0,255,0)); } -class NioUI : public Fl_Window +NioUI::NioUI() + :Fl_Window(200,100,400,400,"New IO Controls"), + foo(20,50,100,25) { - public: - NioUI() - :Fl_Window(200,100,400,400,"New IO Controls"), - foo(20,50,100,25) - { - Fl::scheme("plastic"); - resizable(this); - size_range(400,300); - show(); - } - private: - Pack foo; -}; - - - -int main() -{ - NioUI myUI; - return Fl::run(); + Fl::scheme("plastic"); + resizable(this); + size_range(400,300); } + +//int main() +//{ +// NioUI myUI; +// return Fl::run(); +//} diff --git a/src/UI/NioUI.h b/src/UI/NioUI.h @@ -0,0 +1,27 @@ +#ifndef NIOUI_H +#define NIOUT_H + +#include <FL/Fl.H> +#include <FL/Fl_Light_Button.H> +#include <FL/Fl_Window.H> +#include <FL/Fl_Pack.H> +#include <FL/Enumerations.H> + +class Pack : public Fl_Pack +{ + public: + Pack(int x, int y, int w, int h); + private: + Fl_Light_Button b1,b2,b3; + static void nioTogglei(Fl_Widget *wid, void *name); +}; + +class NioUI : public Fl_Window +{ + public: + NioUI(); + private: + Pack foo; +}; +#endif + diff --git a/src/main.cpp b/src/main.cpp @@ -81,8 +81,6 @@ int swaplr = 0; //1 for left-right swapping bool usejackit = false; #include "Nio/OutMgr.h" -//temporary include (remove once the OutMgr can bootstrap itself) -#include "Nio/NulEngine.h" #ifdef USE_LASH @@ -572,13 +570,13 @@ int main(int argc, char *argv[]) //Output Bootstrapping sysOut=NULL; sysOut = new OutMgr(master); - if(sysOut); - AudioOut *tmp = new NulEngine(sysOut); + //if(sysOut); + //AudioOut *tmp = new NulEngine(sysOut); //tmp->openAudio(); //tmp->openAudio(); //AudioOut *tmp = new OssEngine(sysOut); - if(tmp) - sysOut->add(tmp); + //if(tmp) + // sysOut->add(tmp); sysOut->run();