zynaddsubfx

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

commit c4e9eff7225d11bc4f3ef2e525bb945f03015206
parent 810948a262fec5c88decc6ac5be5abf9d0f32bcd
Author: fundamental <[email protected]>
Date:   Mon, 25 Jul 2011 02:38:53 -0400

Nio: implemented autoconnect for jack

-a or --auto-connect now connects to JACK at startup

Diffstat:
Msrc/Nio/JackEngine.cpp | 18++++++++++++++++++
Msrc/Nio/Nio.cpp | 3++-
Msrc/Nio/Nio.h | 1+
Msrc/main.cpp | 11++++++++---
4 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/src/Nio/JackEngine.cpp b/src/Nio/JackEngine.cpp @@ -22,6 +22,7 @@ #include <jack/midiport.h> #include <fcntl.h> #include <sys/stat.h> +#include <cassert> #include "Nio.h" #include "InMgr.h" @@ -173,6 +174,23 @@ bool JackEngine::openAudio() { audio.jackSamplerate = jack_get_sample_rate(jackClient); audio.jackNframes = jack_get_buffer_size(jackClient); + + //Attempt to autoConnect when specified + if(Nio::getInstance().autoConnect) + { + const char **outPorts = jack_get_ports(jackClient, NULL, NULL, + JackPortIsPhysical|JackPortIsInput); + if(outPorts != NULL) { + //Verify that stereo is available + assert(outPorts[0]); + assert(outPorts[1]); + + //Connect to physical outputs + jack_connect(jackClient, jack_port_name(audio.ports[0]), outPorts[0]); + jack_connect(jackClient, jack_port_name(audio.ports[1]), outPorts[1]); + } else + cerr << "Warning, No outputs to autoconnect to" << endl; + } return true; } else diff --git a/src/Nio/Nio.cpp b/src/Nio/Nio.cpp @@ -14,7 +14,8 @@ Nio &Nio::getInstance() } Nio::Nio() -:in(InMgr::getInstance()),//Enable input wrapper +:autoConnect(false), + in(InMgr::getInstance()),//Enable input wrapper out(OutMgr::getInstance()),//Initialize the Output Systems eng(EngineMgr::getInstance()),//Initialize The Engines postfix("")//no default postfix diff --git a/src/Nio/Nio.h b/src/Nio/Nio.h @@ -30,6 +30,7 @@ class Nio std::string getSource() const; std::string getSink() const; + bool autoConnect; private: Nio(); diff --git a/src/main.cpp b/src/main.cpp @@ -294,6 +294,7 @@ int main(int argc, char *argv[]) {"dummy", 2, NULL, 'Y'}, {"help", 2, NULL, 'h'}, {"named", 1, NULL, 'N'}, + {"auto-connect", 0, NULL, 'a'}, {"output", 1, NULL, 'O'}, {"input", 1, NULL, 'I'}, {0, 0, 0, 0} @@ -307,10 +308,10 @@ int main(int argc, char *argv[]) while(1) { /**\todo check this process for a small memory leak*/ #if OS_LINUX || OS_CYGWIN - opt = getopt_long(argc, argv, "l:L:r:b:o:I:O:N:hSDUY", opts, &option_index); + opt = getopt_long(argc, argv, "l:L:r:b:o:I:O:N:haSDUY", opts, &option_index); char *optarguments = optarg; #elif OS_WINDOWS - opt = getopt(argc, argv, "l:L:r:b:o:I:O:N:hSDUY", &option_index); + opt = getopt(argc, argv, "l:L:r:b:o:I:O:N:haSDUY", &option_index); char *optarguments = &winoptarguments[0]; #else char *optarguments = NULL; @@ -391,6 +392,9 @@ int main(int argc, char *argv[]) exit(1); } break; + case 'a': + Nio::getInstance().autoConnect = true; + break; case '?': cerr << "ERROR:Bad option or parameter.\n" << endl; exitwithhelp = 1; @@ -409,7 +413,8 @@ int main(int argc, char *argv[]) << " -S , --swap\t\t\t\t Swap Left <--> Right\n" << " -D , --dump\t\t\t\t Dumps midi note ON/OFF commands\n" << " -U , --no-gui\t\t\t\t Run ZynAddSubFX without user interface\n" - << " -N , --named\t\t\t\t postfix IO Name when possible\n" + << " -N , --named\t\t\t\t Postfix IO Name when possible\n" + << " -a , --auto-connect\t\t\t AutoConnect when using JACK\n" << " -O , --output\t\t\t\t Set Output Engine\n" << " -I , --input\t\t\t\t Set Input Engine" << endl;