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.

181 lines
4.5KB

  1. /*
  2. * Carla LinuxSampler utils
  3. * Copyright (C) 2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the COPYING file
  16. */
  17. #ifndef CARLA_LINUXSAMPLER_UTILS_H
  18. #define CARLA_LINUXSAMPLER_UTILS_H
  19. #include <linuxsampler/engines/Engine.h>
  20. #include <linuxsampler/Sampler.h>
  21. #include <set>
  22. #include <vector>
  23. namespace LinuxSampler {
  24. // -----------------------------------------------------------------------
  25. class EngineFactory
  26. {
  27. public:
  28. static std::vector<String> AvailableEngineTypes();
  29. static String AvailableEngineTypesAsString();
  30. static Engine* Create(String EngineType) throw (Exception);
  31. static void Destroy(Engine* pEngine);
  32. static const std::set<Engine*>& EngineInstances();
  33. protected:
  34. static void Erase(Engine* pEngine);
  35. friend class Engine;
  36. };
  37. #ifndef BUILD_NATIVE
  38. #include "carla_plugin.h"
  39. // -----------------------------------------------------------------------
  40. // LinuxSampler static values
  41. static const float VOLUME_MAX = 3.16227766f; // +10 dB
  42. static const float VOLUME_MIN = 0.0f; // -inf dB
  43. // -----------------------------------------------------------------------
  44. // LinuxSampler AudioOutputDevice Plugin
  45. class AudioOutputDevicePlugin : public AudioOutputDevice
  46. {
  47. public:
  48. AudioOutputDevicePlugin(CarlaBackend::CarlaEngine* const engine, CarlaBackend::CarlaPlugin* const plugin)
  49. : AudioOutputDevice(std::map<String, DeviceCreationParameter*>()),
  50. m_engine(engine),
  51. m_plugin(plugin)
  52. {
  53. CARLA_ASSERT(engine);
  54. CARLA_ASSERT(plugin);
  55. }
  56. // -------------------------------------------------------------------
  57. // LinuxSampler virtual methods
  58. void Play()
  59. {
  60. }
  61. bool IsPlaying()
  62. {
  63. return m_engine->isRunning() && m_plugin->enabled();
  64. }
  65. void Stop()
  66. {
  67. }
  68. uint MaxSamplesPerCycle()
  69. {
  70. return m_engine->getBufferSize();
  71. }
  72. uint SampleRate()
  73. {
  74. return m_engine->getSampleRate();
  75. }
  76. String Driver()
  77. {
  78. return "AudioOutputDevicePlugin";
  79. }
  80. AudioChannel* CreateChannel(uint channelNr)
  81. {
  82. return new AudioChannel(channelNr, nullptr, 0);
  83. }
  84. // -------------------------------------------------------------------
  85. // Give public access to the RenderAudio call
  86. int Render(uint samples)
  87. {
  88. return RenderAudio(samples);
  89. }
  90. private:
  91. CarlaBackend::CarlaEngine* const m_engine;
  92. CarlaBackend::CarlaPlugin* const m_plugin;
  93. };
  94. // -----------------------------------------------------------------------
  95. // LinuxSampler MidiInputDevice Plugin
  96. class MidiInputDevicePlugin : public MidiInputDevice
  97. {
  98. public:
  99. MidiInputDevicePlugin(Sampler* const sampler)
  100. : MidiInputDevice(std::map<String, DeviceCreationParameter*>(), sampler)
  101. {
  102. }
  103. // -------------------------------------------------------------------
  104. // LinuxSampler virtual methods
  105. void Listen()
  106. {
  107. }
  108. void StopListen()
  109. {
  110. }
  111. String Driver()
  112. {
  113. return "MidiInputDevicePlugin";
  114. }
  115. MidiInputPort* CreateMidiPort()
  116. {
  117. return new MidiInputPortPlugin(this, Ports.size());
  118. }
  119. // -------------------------------------------------------------------
  120. // Properly delete port (deconstructor is protected)
  121. void DeleteMidiPort(MidiInputPort* const port)
  122. {
  123. delete (MidiInputPortPlugin*)port;
  124. }
  125. // -------------------------------------------------------------------
  126. // MIDI Port implementation for this plugin MIDI input driver
  127. // (Constructor and deconstructor are protected)
  128. class MidiInputPortPlugin : public MidiInputPort
  129. {
  130. protected:
  131. MidiInputPortPlugin(MidiInputDevicePlugin* const device, const int portNumber)
  132. : MidiInputPort(device, portNumber)
  133. {
  134. }
  135. friend class MidiInputDevicePlugin;
  136. };
  137. };
  138. // -----------------------------------------------------------------------
  139. #endif // ! BUILD_NATIVE
  140. } // namespace LinuxSampler
  141. #endif // CARLA_LINUXSAMPLER_UTILS_H