Sine Wave Tutorial build with error messages


#1

Hey guys and gals, new here and really trying to understand C++ while building vsts. I started with a strong understanding of PureData and got interested in building VSTs, but hitting walls due to my not strong C++ abilities.

Anyhow, started off great with the JUCE tutorials and try to build from the ground up by cross referencing the downloadable source file and follow along with the online tutorial, but man, I can not figure what I’m doing wrong here. please help, it’s probably something simple!

I get all sorts of error messages for my MainContentComponent class

#ifndef MAINCOMPONENT_H_INCLUDED
#define MAINCOMPONENT_H_INCLUDED

#include “…/JuceLibraryCode/JuceHeader.h”

class MainContentComponent : public AudioAppComponent,
public Slider::Listener
{
public:
MainContentComponent()
: currentSampleRate (0.0),
currentAngle (0.0),
angleDelta (0.0),
currentFrequency (500.0),
targetFrequency (currentFrequency)
{
addAndMakeVisible (frequencySlider);
frequencySlider.setRange (50.0, 5000.0);
frequencySlider.setSkewFactorFromMidPoint (500.0);
frequencySlider.addListener (this);

    setSize (600, 100);
    setAudioChannels (0, 1); // no inputs, one output
}

~MainContentComponent()
{
    shutdownAudio();
}

void resized() override
{
    frequencySlider.setBounds (10, 10, getWidth() - 20, 20);
}

void sliderValueChanged (Slider* slider) override
{
    if (slider == &frequencySlider)
        targetFrequency = frequencySlider.getValue();
  /*  {
        if (currentSampleRate > 0.0)
            updateAngleDelta();
    }    */
}

void updateAngleDelta()
{
    const double cyclesPerSample = frequencySlider.getValue() / currentSampleRate; // [2]
    angleDelta = cyclesPerSample * 2.0 * double_Pi;                                // [3]
}

void prepareToPlay (int /*samplesPerBlockExpected*/, double sampleRate) override
{
    currentSampleRate = sampleRate;
    updateAngleDelta();
}

void releaseResources() override
{
}

void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override
{
    const float level = 0.125f;
    float* const buffer = bufferToFill.buffer->getWritePointer (0, bufferToFill.startSample);
    
    const double localTargetFrequency = targetFrequency;
    
    if (localTargetFrequency != targetFrequency)
    {
        const double frequencyIncrement = (localTargetFrequency - currentFrequency) /
          bufferToFill.numSamples;
          
          for (int sample = 0; sample < bufferToFill.numSamples; ++sample)
        {
            const float currentSample = (float) std::sin (currentAngle);
            currentFrequency += frequencyIncrement;
            
            updateAngleDelta();
            
            currentAngle += angleDelta;
            buffer[sample] = currentSample * level;
        }
        
        currentFrequency = localTargetFrequency;
        
    else 
        {           
         for (int sample = 0; sample < bufferToFill.numSamples; ++sample)
         {
          const float currentSample = (float) std::sin (currentAngle);
          currentAngle += angleDelta;
          buffer[sample] = currentSample * level;
}

private:
Slider frequencySlider;
double currentSampleRate, currentAngle, angleDelta, currentFrequency, targetFrequency; // [1]

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)

};

Component* createMainContentComponent() { return new MainContentComponent(); }

#endif // MAINCOMPONENT_H_INCLUDED


#2

…and would you mind telling what these error messages are?
At least the first bunch?
And are they compile errors, linker errors, asserts, crashes?
A little more data would be necessary to help… :wink:


#3

You should indent your code by 4 spaces to get it to show correctly in the forum.

And it just looks like your brackets are all over the place, nothing to do with C++!


#4

If I understood you correctly, you have tried setting up a build yourself from scratch without using the Projucer and/or existing project files for Visual Studio or XCode…? I am assuming you are at least using an up to date, standard and supported C++ IDE for building, namely Visual Studio for Windows or XCode for OS-X.

JUCE is a quite complicated C++ library, so when beginning to work with it, especially if you haven’t already worked with C++ build tools, you should just use ready-made project files for Visual Studio or XCode, instead of trying to figure out yourself the needed procedures for building. (If there are no project files, hopefully there’s at least the Jucer file that allows generating the VS or XCode projects with the Projucer.) Later, when you understand things better, you can try setting up customised builds yourself. As a C++ newbie you are not really going to benefit much from getting deeply involved with the complexities of setting up builds from scratch.

Or maybe I misunderstood and it’s just about what Jules explained above and you didn’t observe the {} brackets correctly. C++ compilers will be merciless about errors like that as those brackets are such a fundamental part of the language syntax.


#5

yeah, I should be more precise in my explanation. I’m using JUCE, and my IDE is xcode. I ‘build from scratch’, meaning I use JUCE as a starting point by creating a new project under the standalone audio DSP option. I’ll take a look at my brackets, I may have over done it when debugging/trying to build it.


#6

I went back and checked out my brackets. It was absolutely the culprit. Dammit, what a noob move :expressionless:

I was distracted by the compiler telling me that specific expressions didn’t exist and another few errors. …It was probably because it was running the whole set of code as one object and therefor wasn’t declaring properly.

Thanks guys!