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.

159 lines
4.6KB

  1. /*
  2. ==============================================================================
  3. This file was auto-generated by the Jucer!
  4. It contains the basic startup code for a Juce application.
  5. ==============================================================================
  6. */
  7. #include "PluginProcessor.h"
  8. #include "PluginEditor.h"
  9. #include "InternalFilters.h"
  10. AudioProcessor* JUCE_CALLTYPE createPluginFilter();
  11. //==============================================================================
  12. JuceDemoHostAudioProcessor::JuceDemoHostAudioProcessor()
  13. : formatManager(),
  14. graph (formatManager),
  15. midiKeyState (nullptr)
  16. {
  17. PropertiesFile::Options options;
  18. options.applicationName = "Juce Audio Plugin Host";
  19. options.filenameSuffix = "settings";
  20. options.osxLibrarySubFolder = "Preferences";
  21. appProperties = new ApplicationProperties();
  22. appProperties->setStorageParameters(options);
  23. formatManager.addDefaultFormats();
  24. formatManager.addFormat(new InternalPluginFormat());
  25. graph.ready(appProperties);
  26. graph.getGraph().setPlayConfigDetails(getTotalNumInputChannels(), getTotalNumOutputChannels(), getSampleRate(), getBlockSize());
  27. }
  28. JuceDemoHostAudioProcessor::~JuceDemoHostAudioProcessor()
  29. {
  30. graph.clear();
  31. }
  32. //==============================================================================
  33. void JuceDemoHostAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
  34. {
  35. graph.getGraph().setPlayConfigDetails(getTotalNumInputChannels(), getTotalNumOutputChannels(), sampleRate, samplesPerBlock);
  36. graph.getGraph().prepareToPlay(sampleRate, samplesPerBlock);
  37. {
  38. const ScopedLock csl(midiKeyMutex);
  39. if (midiKeyState != nullptr)
  40. midiKeyState->reset();
  41. }
  42. }
  43. void JuceDemoHostAudioProcessor::releaseResources()
  44. {
  45. graph.getGraph().releaseResources();
  46. }
  47. void JuceDemoHostAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  48. {
  49. const int numSamples = buffer.getNumSamples();
  50. graph.getGraph().setPlayHead (getPlayHead());
  51. {
  52. const ScopedLock csl(midiKeyMutex);
  53. if (midiKeyState != nullptr)
  54. midiKeyState->processNextMidiBuffer(midiMessages, 0, numSamples, true);
  55. }
  56. graph.getGraph().processBlock(buffer, midiMessages);
  57. // In case we have more outputs than inputs, we'll clear any output
  58. // channels that didn't contain input data, (because these aren't
  59. // guaranteed to be empty - they may contain garbage).
  60. for (int i = getTotalNumInputChannels(); i < getTotalNumOutputChannels(); ++i)
  61. buffer.clear (i, 0, numSamples);
  62. }
  63. //==============================================================================
  64. AudioProcessorEditor* JuceDemoHostAudioProcessor::createEditor()
  65. {
  66. return new JuceDemoHostAudioProcessorEditor (*this);
  67. }
  68. //==============================================================================
  69. void JuceDemoHostAudioProcessor::getStateInformation (MemoryBlock& destData)
  70. {
  71. ScopedPointer<XmlElement> xmlState (graph.createXml());
  72. copyXmlToBinary (*xmlState, destData);
  73. }
  74. void JuceDemoHostAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
  75. {
  76. ScopedPointer<XmlElement> xmlState (getXmlFromBinary (data, sizeInBytes));
  77. if (xmlState != nullptr && xmlState->hasTagName("FILTERGRAPH"))
  78. graph.restoreFromXml(*xmlState);
  79. }
  80. const String JuceDemoHostAudioProcessor::getInputChannelName (const int channelIndex) const
  81. {
  82. return String (channelIndex + 1);
  83. }
  84. const String JuceDemoHostAudioProcessor::getOutputChannelName (const int channelIndex) const
  85. {
  86. return String (channelIndex + 1);
  87. }
  88. bool JuceDemoHostAudioProcessor::isInputChannelStereoPair (int /*index*/) const
  89. {
  90. return true;
  91. }
  92. bool JuceDemoHostAudioProcessor::isOutputChannelStereoPair (int /*index*/) const
  93. {
  94. return true;
  95. }
  96. bool JuceDemoHostAudioProcessor::acceptsMidi() const
  97. {
  98. #if JucePlugin_WantsMidiInput
  99. return true;
  100. #else
  101. return false;
  102. #endif
  103. }
  104. bool JuceDemoHostAudioProcessor::producesMidi() const
  105. {
  106. #if JucePlugin_ProducesMidiOutput
  107. return true;
  108. #else
  109. return false;
  110. #endif
  111. }
  112. bool JuceDemoHostAudioProcessor::silenceInProducesSilenceOut() const
  113. {
  114. return false;
  115. }
  116. double JuceDemoHostAudioProcessor::getTailLengthSeconds() const
  117. {
  118. return 0.0;
  119. }
  120. //==============================================================================
  121. // This creates new instances of the plugin..
  122. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  123. {
  124. return new JuceDemoHostAudioProcessor();
  125. }