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.

162 lines
3.0KB

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