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.

174 lines
3.3KB

  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. eng->stop();
  49. }
  50. void Nio::setDefaultSource(string name)
  51. {
  52. std::transform(name.begin(), name.end(), name.begin(), ::toupper);
  53. defaultSource = name;
  54. }
  55. void Nio::setDefaultSink(string name)
  56. {
  57. std::transform(name.begin(), name.end(), name.begin(), ::toupper);
  58. defaultSink = name;
  59. }
  60. bool Nio::setSource(string name)
  61. {
  62. return in->setSource(name);
  63. }
  64. bool Nio::setSink(string name)
  65. {
  66. return out->setSink(name);
  67. }
  68. void Nio::setPostfix(std::string post)
  69. {
  70. postfix = post;
  71. }
  72. std::string Nio::getPostfix(void)
  73. {
  74. return postfix;
  75. }
  76. set<string> Nio::getSources(void)
  77. {
  78. set<string> sources;
  79. for(std::list<Engine *>::iterator itr = eng->engines.begin();
  80. itr != eng->engines.end(); ++itr)
  81. if(dynamic_cast<MidiIn *>(*itr))
  82. sources.insert((*itr)->name);
  83. return sources;
  84. }
  85. set<string> Nio::getSinks(void)
  86. {
  87. set<string> sinks;
  88. for(std::list<Engine *>::iterator itr = eng->engines.begin();
  89. itr != eng->engines.end(); ++itr)
  90. if(dynamic_cast<AudioOut *>(*itr))
  91. sinks.insert((*itr)->name);
  92. return sinks;
  93. }
  94. string Nio::getSource()
  95. {
  96. return in->getSource();
  97. }
  98. string Nio::getSink()
  99. {
  100. return out->getSink();
  101. }
  102. #if JACK
  103. #include <jack/jack.h>
  104. void Nio::preferedSampleRate(unsigned &rate)
  105. {
  106. #if __linux__
  107. //avoid checking in with jack if it's off
  108. FILE *ps = popen("ps aux", "r");
  109. char buffer[4096];
  110. while(fgets(buffer, sizeof(buffer), ps))
  111. if(strstr(buffer, "jack"))
  112. break;
  113. fclose(ps);
  114. if(!strstr(buffer, "jack"))
  115. return;
  116. #endif
  117. jack_client_t *client = jack_client_open("temp-client",
  118. JackNoStartServer, 0);
  119. if(client) {
  120. rate = jack_get_sample_rate(client);
  121. jack_client_close(client);
  122. }
  123. }
  124. #else
  125. void Nio::preferedSampleRate(unsigned &)
  126. {}
  127. #endif
  128. void Nio::masterSwap(Master *master)
  129. {
  130. in->setMaster(master);
  131. out->setMaster(master);
  132. }
  133. void Nio::waveNew(class WavFile *wave)
  134. {
  135. out->wave->newFile(wave);
  136. }
  137. void Nio::waveStart(void)
  138. {
  139. out->wave->Start();
  140. }
  141. void Nio::waveStop(void)
  142. {
  143. out->wave->Stop();
  144. }
  145. void Nio::waveEnd(void)
  146. {
  147. out->wave->destroyFile();
  148. }