Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Nio.cpp 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #include "Nio.h"
  2. #include "OutMgr.h"
  3. #include "InMgr.h"
  4. #include "EngineMgr.h"
  5. #include "MidiIn.h"
  6. #include "AudioOut.h"
  7. #include "WavEngine.h"
  8. #include "../Misc/Config.h"
  9. #include <cstring>
  10. #include <iostream>
  11. #include <algorithm>
  12. using std::string;
  13. using std::set;
  14. using std::cerr;
  15. using std::endl;
  16. #ifndef IN_DEFAULT
  17. #define IN_DEFAULT "NULL"
  18. #endif
  19. #ifndef OUT_DEFAULT
  20. #define OUT_DEFAULT "NULL"
  21. #endif
  22. InMgr *in = NULL;
  23. OutMgr *out = NULL;
  24. EngineMgr *eng = NULL;
  25. string postfix;
  26. bool Nio::autoConnect = false;
  27. bool Nio::pidInClientName = false;
  28. string Nio::defaultSource = IN_DEFAULT;
  29. string Nio::defaultSink = OUT_DEFAULT;
  30. void Nio::init(const SYNTH_T &synth, const oss_devs_t& oss_devs,
  31. class Master *master)
  32. {
  33. in = &InMgr::getInstance(); //Enable input wrapper
  34. out = &OutMgr::getInstance(&synth); //Initialize the Output Systems
  35. eng = &EngineMgr::getInstance(&synth, &oss_devs); //Initialize the Engines
  36. in->setMaster(master);
  37. out->setMaster(master);
  38. }
  39. bool Nio::start()
  40. {
  41. if(eng)
  42. return eng->start();
  43. else
  44. return false;
  45. }
  46. void Nio::stop()
  47. {
  48. if(eng)
  49. eng->stop();
  50. }
  51. void Nio::setDefaultSource(string name)
  52. {
  53. std::transform(name.begin(), name.end(), name.begin(), ::toupper);
  54. defaultSource = name;
  55. }
  56. void Nio::setDefaultSink(string name)
  57. {
  58. std::transform(name.begin(), name.end(), name.begin(), ::toupper);
  59. defaultSink = name;
  60. }
  61. bool Nio::setSource(string name)
  62. {
  63. return in->setSource(name);
  64. }
  65. bool Nio::setSink(string name)
  66. {
  67. return out->setSink(name);
  68. }
  69. void Nio::setPostfix(std::string post)
  70. {
  71. postfix = post;
  72. }
  73. std::string Nio::getPostfix(void)
  74. {
  75. return postfix;
  76. }
  77. set<string> Nio::getSources(void)
  78. {
  79. set<string> sources;
  80. for(std::list<Engine *>::iterator itr = eng->engines.begin();
  81. itr != eng->engines.end(); ++itr)
  82. if(dynamic_cast<MidiIn *>(*itr))
  83. sources.insert((*itr)->name);
  84. return sources;
  85. }
  86. set<string> Nio::getSinks(void)
  87. {
  88. set<string> sinks;
  89. for(std::list<Engine *>::iterator itr = eng->engines.begin();
  90. itr != eng->engines.end(); ++itr)
  91. if(dynamic_cast<AudioOut *>(*itr))
  92. sinks.insert((*itr)->name);
  93. return sinks;
  94. }
  95. string Nio::getSource()
  96. {
  97. return in->getSource();
  98. }
  99. string Nio::getSink()
  100. {
  101. return out->getSink();
  102. }
  103. #if JACK
  104. #include <jack/jack.h>
  105. void Nio::preferedSampleRate(unsigned &rate)
  106. {
  107. #if __linux__
  108. //avoid checking in with jack if it's off
  109. FILE *ps = popen("ps aux", "r");
  110. char buffer[4096];
  111. while(fgets(buffer, sizeof(buffer), ps))
  112. if(strstr(buffer, "jack"))
  113. break;
  114. fclose(ps);
  115. if(!strstr(buffer, "jack"))
  116. return;
  117. #endif
  118. jack_client_t *client = jack_client_open("temp-client",
  119. JackNoStartServer, 0);
  120. if(client) {
  121. rate = jack_get_sample_rate(client);
  122. jack_client_close(client);
  123. }
  124. }
  125. #else
  126. void Nio::preferedSampleRate(unsigned &)
  127. {}
  128. #endif
  129. void Nio::masterSwap(Master *master)
  130. {
  131. in->setMaster(master);
  132. out->setMaster(master);
  133. }
  134. void Nio::waveNew(class WavFile *wave)
  135. {
  136. out->wave->newFile(wave);
  137. }
  138. void Nio::waveStart(void)
  139. {
  140. out->wave->Start();
  141. }
  142. void Nio::waveStop(void)
  143. {
  144. out->wave->Stop();
  145. }
  146. void Nio::waveEnd(void)
  147. {
  148. out->wave->destroyFile();
  149. }