Collection of tools useful for audio production
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.

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