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.

139 lines
2.5KB

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