├── .gitignore ├── Source ├── PluginEditor.cpp ├── PluginEditor.h ├── PluginProcessor.cpp └── PluginProcessor.h └── basicOscillator.jucer /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /JuceLibraryCode/ 3 | /Builds/ 4 | -------------------------------------------------------------------------------- /Source/PluginEditor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================== 3 | 4 | This file contains the basic framework code for a JUCE plugin editor. 5 | 6 | ============================================================================== 7 | */ 8 | 9 | #include "PluginProcessor.h" 10 | #include "PluginEditor.h" 11 | 12 | //============================================================================== 13 | BasicOscillatorAudioProcessorEditor::BasicOscillatorAudioProcessorEditor (BasicOscillatorAudioProcessor& p) 14 | : AudioProcessorEditor (&p), audioProcessor (p) 15 | { 16 | // Make sure that before the constructor has finished, you've set the 17 | // editor's size to whatever you need it to be. 18 | setSize (400, 300); 19 | } 20 | 21 | BasicOscillatorAudioProcessorEditor::~BasicOscillatorAudioProcessorEditor() 22 | { 23 | } 24 | 25 | //============================================================================== 26 | void BasicOscillatorAudioProcessorEditor::paint (juce::Graphics& g) 27 | { 28 | // (Our component is opaque, so we must completely fill the background with a solid colour) 29 | g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId)); 30 | 31 | g.setColour (juce::Colours::white); 32 | g.setFont (15.0f); 33 | g.drawFittedText ("Hello World!", getLocalBounds(), juce::Justification::centred, 1); 34 | } 35 | 36 | void BasicOscillatorAudioProcessorEditor::resized() 37 | { 38 | // This is generally where you'll want to lay out the positions of any 39 | // subcomponents in your editor.. 40 | } 41 | -------------------------------------------------------------------------------- /Source/PluginEditor.h: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================== 3 | 4 | This file contains the basic framework code for a JUCE plugin editor. 5 | 6 | ============================================================================== 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include "PluginProcessor.h" 13 | 14 | //============================================================================== 15 | /** 16 | */ 17 | class BasicOscillatorAudioProcessorEditor : public juce::AudioProcessorEditor 18 | { 19 | public: 20 | BasicOscillatorAudioProcessorEditor (BasicOscillatorAudioProcessor&); 21 | ~BasicOscillatorAudioProcessorEditor() override; 22 | 23 | //============================================================================== 24 | void paint (juce::Graphics&) override; 25 | void resized() override; 26 | 27 | private: 28 | // This reference is provided as a quick way for your editor to 29 | // access the processor object that created it. 30 | BasicOscillatorAudioProcessor& audioProcessor; 31 | 32 | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BasicOscillatorAudioProcessorEditor) 33 | }; 34 | -------------------------------------------------------------------------------- /Source/PluginProcessor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================== 3 | 4 | This file contains the basic framework code for a JUCE plugin processor. 5 | 6 | ============================================================================== 7 | */ 8 | 9 | #include "PluginProcessor.h" 10 | #include "PluginEditor.h" 11 | 12 | //============================================================================== 13 | BasicOscillatorAudioProcessor::BasicOscillatorAudioProcessor() 14 | #ifndef JucePlugin_PreferredChannelConfigurations 15 | : AudioProcessor (BusesProperties() 16 | #if ! JucePlugin_IsMidiEffect 17 | #if ! JucePlugin_IsSynth 18 | .withInput ("Input", juce::AudioChannelSet::stereo(), false) 19 | #endif 20 | .withOutput ("Output", juce::AudioChannelSet::stereo(), true) 21 | #endif 22 | ) 23 | #endif 24 | { 25 | } 26 | 27 | BasicOscillatorAudioProcessor::~BasicOscillatorAudioProcessor() 28 | { 29 | } 30 | 31 | //============================================================================== 32 | const juce::String BasicOscillatorAudioProcessor::getName() const 33 | { 34 | return JucePlugin_Name; 35 | } 36 | 37 | bool BasicOscillatorAudioProcessor::acceptsMidi() const 38 | { 39 | #if JucePlugin_WantsMidiInput 40 | return true; 41 | #else 42 | return false; 43 | #endif 44 | } 45 | 46 | bool BasicOscillatorAudioProcessor::producesMidi() const 47 | { 48 | #if JucePlugin_ProducesMidiOutput 49 | return true; 50 | #else 51 | return false; 52 | #endif 53 | } 54 | 55 | bool BasicOscillatorAudioProcessor::isMidiEffect() const 56 | { 57 | #if JucePlugin_IsMidiEffect 58 | return true; 59 | #else 60 | return false; 61 | #endif 62 | } 63 | 64 | double BasicOscillatorAudioProcessor::getTailLengthSeconds() const 65 | { 66 | return 0.0; 67 | } 68 | 69 | int BasicOscillatorAudioProcessor::getNumPrograms() 70 | { 71 | return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs, 72 | // so this should be at least 1, even if you're not really implementing programs. 73 | } 74 | 75 | int BasicOscillatorAudioProcessor::getCurrentProgram() 76 | { 77 | return 0; 78 | } 79 | 80 | void BasicOscillatorAudioProcessor::setCurrentProgram (int index) 81 | { 82 | } 83 | 84 | const juce::String BasicOscillatorAudioProcessor::getProgramName (int index) 85 | { 86 | return {}; 87 | } 88 | 89 | void BasicOscillatorAudioProcessor::changeProgramName (int index, const juce::String& newName) 90 | { 91 | } 92 | 93 | //============================================================================== 94 | void BasicOscillatorAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock) 95 | { 96 | juce::dsp::ProcessSpec spec; 97 | spec.maximumBlockSize = samplesPerBlock; 98 | spec.sampleRate = sampleRate; 99 | spec.numChannels = getTotalNumOutputChannels(); 100 | 101 | osc.prepare (spec); 102 | gain.prepare (spec); 103 | 104 | osc.setFrequency (220.0f); 105 | gain.setGainLinear (0.01f); 106 | } 107 | 108 | void BasicOscillatorAudioProcessor::releaseResources() 109 | { 110 | // When playback stops, you can use this as an opportunity to free up any 111 | // spare memory, etc. 112 | } 113 | 114 | #ifndef JucePlugin_PreferredChannelConfigurations 115 | bool BasicOscillatorAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const 116 | { 117 | #if JucePlugin_IsMidiEffect 118 | juce::ignoreUnused (layouts); 119 | return true; 120 | #else 121 | // This is the place where you check if the layout is supported. 122 | // In this template code we only support mono or stereo. 123 | if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono() 124 | && layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo()) 125 | return false; 126 | 127 | // This checks if the input layout matches the output layout 128 | #if ! JucePlugin_IsSynth 129 | if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet()) 130 | return false; 131 | #endif 132 | 133 | return true; 134 | #endif 135 | } 136 | #endif 137 | 138 | void BasicOscillatorAudioProcessor::processBlock (juce::AudioBuffer& buffer, juce::MidiBuffer& midiMessages) 139 | { 140 | juce::ScopedNoDenormals noDenormals; 141 | auto totalNumInputChannels = getTotalNumInputChannels(); 142 | auto totalNumOutputChannels = getTotalNumOutputChannels(); 143 | 144 | for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i) 145 | buffer.clear (i, 0, buffer.getNumSamples()); 146 | 147 | juce::dsp::AudioBlock audioBlock { buffer }; 148 | osc.process (juce::dsp::ProcessContextReplacing (audioBlock)); 149 | gain.process (juce::dsp::ProcessContextReplacing (audioBlock)); 150 | } 151 | 152 | //============================================================================== 153 | bool BasicOscillatorAudioProcessor::hasEditor() const 154 | { 155 | return true; // (change this to false if you choose to not supply an editor) 156 | } 157 | 158 | juce::AudioProcessorEditor* BasicOscillatorAudioProcessor::createEditor() 159 | { 160 | return new BasicOscillatorAudioProcessorEditor (*this); 161 | } 162 | 163 | //============================================================================== 164 | void BasicOscillatorAudioProcessor::getStateInformation (juce::MemoryBlock& destData) 165 | { 166 | // You should use this method to store your parameters in the memory block. 167 | // You could do that either as raw data, or use the XML or ValueTree classes 168 | // as intermediaries to make it easy to save and load complex data. 169 | } 170 | 171 | void BasicOscillatorAudioProcessor::setStateInformation (const void* data, int sizeInBytes) 172 | { 173 | // You should use this method to restore your parameters from this memory block, 174 | // whose contents will have been created by the getStateInformation() call. 175 | } 176 | 177 | //============================================================================== 178 | // This creates new instances of the plugin.. 179 | juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter() 180 | { 181 | return new BasicOscillatorAudioProcessor(); 182 | } 183 | -------------------------------------------------------------------------------- /Source/PluginProcessor.h: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================== 3 | 4 | This file contains the basic framework code for a JUCE plugin processor. 5 | 6 | ============================================================================== 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | //============================================================================== 14 | /** 15 | */ 16 | class BasicOscillatorAudioProcessor : public juce::AudioProcessor 17 | { 18 | public: 19 | //============================================================================== 20 | BasicOscillatorAudioProcessor(); 21 | ~BasicOscillatorAudioProcessor() override; 22 | 23 | //============================================================================== 24 | void prepareToPlay (double sampleRate, int samplesPerBlock) override; 25 | void releaseResources() override; 26 | 27 | #ifndef JucePlugin_PreferredChannelConfigurations 28 | bool isBusesLayoutSupported (const BusesLayout& layouts) const override; 29 | #endif 30 | 31 | void processBlock (juce::AudioBuffer&, juce::MidiBuffer&) override; 32 | 33 | //============================================================================== 34 | juce::AudioProcessorEditor* createEditor() override; 35 | bool hasEditor() const override; 36 | 37 | //============================================================================== 38 | const juce::String getName() const override; 39 | 40 | bool acceptsMidi() const override; 41 | bool producesMidi() const override; 42 | bool isMidiEffect() const override; 43 | double getTailLengthSeconds() const override; 44 | 45 | //============================================================================== 46 | int getNumPrograms() override; 47 | int getCurrentProgram() override; 48 | void setCurrentProgram (int index) override; 49 | const juce::String getProgramName (int index) override; 50 | void changeProgramName (int index, const juce::String& newName) override; 51 | 52 | //============================================================================== 53 | void getStateInformation (juce::MemoryBlock& destData) override; 54 | void setStateInformation (const void* data, int sizeInBytes) override; 55 | 56 | private: 57 | //juce::dsp::Oscillator osc { [](float x) { return std::sin (x); }}; 58 | juce::dsp::Oscillator osc { [](float x) { return x < 0.0f ? -1.0f : 1.0f; }, 200 }; 59 | juce::dsp::Gain gain; 60 | 61 | // return std::sin (x); //Sine Wave 62 | // return x / MathConstants::pi; // Saw Wave 63 | // return x < 0.0f ? -1.0f : 1.0f; // Square Wave 64 | 65 | //============================================================================== 66 | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BasicOscillatorAudioProcessor) 67 | }; 68 | -------------------------------------------------------------------------------- /basicOscillator.jucer: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 9 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | --------------------------------------------------------------------------------