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.

163 lines
3.8KB

  1. /*
  2. * Carla common LinuxSampler code
  3. * Copyright (C) 2012 Filipe Coelho <falktx@gmail.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_INCLUDES_H
  18. #define CARLA_LINUXSAMPLER_INCLUDES_H
  19. #include <linuxsampler/engines/Engine.h>
  20. #include <linuxsampler/Sampler.h>
  21. #include <set>
  22. #include <vector>
  23. namespace LinuxSampler {
  24. class EngineFactory
  25. {
  26. public:
  27. static std::vector<String> AvailableEngineTypes();
  28. static String AvailableEngineTypesAsString();
  29. static Engine* Create(String EngineType) throw (Exception);
  30. static void Destroy(Engine* pEngine);
  31. static const std::set<Engine*>& EngineInstances();
  32. protected:
  33. static void Erase(Engine* pEngine);
  34. friend class Engine;
  35. };
  36. #ifndef BUILD_NATIVE
  37. #include "carla_plugin.h"
  38. static const float VOLUME_MAX = 3.16227766f; // +10 dB
  39. static const float VOLUME_MIN = 0.0f; // -inf dB
  40. class AudioOutputDevicePlugin : public AudioOutputDevice
  41. {
  42. public:
  43. AudioOutputDevicePlugin(CarlaBackend::CarlaEngine* const engine, CarlaBackend::CarlaPlugin* const plugin) :
  44. AudioOutputDevice(std::map<String, DeviceCreationParameter*>()),
  45. m_engine(engine),
  46. m_plugin(plugin)
  47. {
  48. }
  49. // -------------------------------------------------------------------
  50. // LinuxSampler virtual methods
  51. void Play()
  52. {
  53. }
  54. bool IsPlaying()
  55. {
  56. return m_engine->isRunning() && m_plugin->enabled();
  57. }
  58. void Stop()
  59. {
  60. }
  61. uint MaxSamplesPerCycle()
  62. {
  63. return m_engine->getBufferSize();
  64. }
  65. uint SampleRate()
  66. {
  67. return m_engine->getSampleRate();
  68. }
  69. String Driver()
  70. {
  71. return "AudioOutputDevicePlugin";
  72. }
  73. AudioChannel* CreateChannel(uint channelNr)
  74. {
  75. return new AudioChannel(channelNr, nullptr, 0);
  76. }
  77. // -------------------------------------------------------------------
  78. int Render(uint samples)
  79. {
  80. return RenderAudio(samples);
  81. }
  82. private:
  83. CarlaBackend::CarlaEngine* const m_engine;
  84. CarlaBackend::CarlaPlugin* const m_plugin;
  85. };
  86. class MidiInputDevicePlugin : public MidiInputDevice
  87. {
  88. public:
  89. MidiInputDevicePlugin(Sampler* const sampler) :
  90. MidiInputDevice(std::map<String, DeviceCreationParameter*>(), sampler)
  91. {
  92. }
  93. // -------------------------------------------------------------------
  94. // LinuxSampler virtual methods
  95. void Listen()
  96. {
  97. }
  98. void StopListen()
  99. {
  100. }
  101. String Driver()
  102. {
  103. return "MidiInputDevicePlugin";
  104. }
  105. MidiInputPort* CreateMidiPort()
  106. {
  107. return new MidiInputPortPlugin(this, Ports.size());
  108. }
  109. // -------------------------------------------------------------------
  110. void DeleteMidiPort(MidiInputPort* const port)
  111. {
  112. delete (MidiInputPortPlugin*)port;
  113. }
  114. // -------------------------------------------------------------------
  115. // MIDI Port implementation for this plugin MIDI input driver
  116. class MidiInputPortPlugin : public MidiInputPort
  117. {
  118. protected:
  119. MidiInputPortPlugin(MidiInputDevicePlugin* const device, const int portNumber) :
  120. MidiInputPort(device, portNumber)
  121. {
  122. }
  123. friend class MidiInputDevicePlugin;
  124. };
  125. };
  126. #endif // ! BUILD_NATIVE
  127. } // namespace LinuxSampler
  128. #endif // CARLA_LINUXSAMPLER_INCLUDES_H