TonicAudio / Tonic

Easy and efficient audio synthesis in C++
The Unlicense
522 stars 63 forks source link

Synth copying (assignment) fails in at least one situation #182

Closed morganpackard closed 11 years ago

morganpackard commented 11 years ago

I've just tried to do the following:

create an openFrameworks project, with a Synth member variable.

In setup, I assign a Synth subclass to the member variable. So like this:

// class member vars ... Synth synth

// in setup synth = SynthSubclass()

Works fine if I just do this:

// class member vars ... SynthSubclass synth

on first glance, looks like BufferFiller's bufferReadPosition_ position gets all out of whack (I was seeing huge values for it).

Obivously this isn't enough info to fix the problem. I want to do some fun coding right now and don't want to stop to fully dig in to the bug. But something's definitely up, and it def. needs to be figured out.

ndonald2 commented 11 years ago

Weird, that is basically exactly what the synthfactory openframeworks demo does, and last I checked that was working fine (a few days ago). I will have a look soon.

On Saturday, June 8, 2013, Morgan Packard wrote:

I've just tried to do the following:

create an openFrameworks project, with a Synth member variable.

In setup, I assign a Synth subclass to the member variable. So like this:

// class member vars ... Synth synth

// in setup synth = SynthSubclass()

Works fine if I just do this:

// class member vars ... SynthSubclass synth

on first glance, looks like BufferFiller's bufferReadPosition_ position gets all out of whack (I was seeing huge values for it).

Obivously this isn't enough info to fix the problem. I want to do some fun coding right now and don't want to stop to fully dig in to the bug. But something's definitely up, and it def. needs to be figured out.

— Reply to this email directly or view it on GitHubhttps://github.com/TonicAudio/Tonic/issues/182 .

Nick Donaldson ndonald2@gmail.com

ndonald2 commented 11 years ago

When you get a chance can you send me an example of the code that was failing? This basic project is working without issues for me using Tonic from the development branch:

Header
#include "ofMain.h"
#include "Tonic.h"

using namespace Tonic;

class testApp : public ofBaseApp{
    public:

        void setup();

        Synth synth;

        ofSoundStream soundStream;
        void audioOut( float * output, int bufferSize, int nChannels );
};
Source
#include "testApp.h"

class TheSynth : public Synth
{
public:
    TheSynth() {
        ControlMetro metro = ControlMetro().bpm(120);
        ADSR env = ADSR(0.001,0.25,0.0,0.1).doesSustain(false).trigger(metro);
        setOutputGen(SineWave().freq(440 + 200 * SineWave().freq(0.1)) * env);
    }
};

//--------------------------------------------------------------
void testApp::setup(){

    const int bufferSize        = 512;
    const int sampleRate        = 44100;
    soundStream.setup(this, 2, 0, sampleRate, bufferSize, 4);

    synth = TheSynth();
}

void testApp::audioOut( float * output, int bufferSize, int nChannels ){
    synth.fillBufferOfFloats(output, bufferSize, nChannels);
}
morganpackard commented 11 years ago

My bad, I think. Looks like I was working off the master branch, which doesn't yet use smart pointers for synths, right?

On Sat, Jun 8, 2013 at 11:02 PM, Nick D. notifications@github.com wrote:

Weird, that is basically exactly what the synthfactory openframeworks demo does, and last I checked that was working fine (a few days ago). I will have a look soon.

On Saturday, June 8, 2013, Morgan Packard wrote:

I've just tried to do the following:

create an openFrameworks project, with a Synth member variable.

In setup, I assign a Synth subclass to the member variable. So like this:

// class member vars ... Synth synth

// in setup synth = SynthSubclass()

Works fine if I just do this:

// class member vars ... SynthSubclass synth

on first glance, looks like BufferFiller's bufferReadPosition_ position gets all out of whack (I was seeing huge values for it).

Obivously this isn't enough info to fix the problem. I want to do some fun coding right now and don't want to stop to fully dig in to the bug. But something's definitely up, and it def. needs to be figured out.

— Reply to this email directly or view it on GitHub< https://github.com/TonicAudio/Tonic/issues/182> .

Nick Donaldson ndonald2@gmail.com

— Reply to this email directly or view it on GitHubhttps://github.com/TonicAudio/Tonic/issues/182#issuecomment-19159911 .

Morgan Packard cell: (720) 891-0122 aim: mpackardatwork twitter: @morganpackard

ndonald2 commented 11 years ago

Right, that makes more sense. The implicit copy constructor on master won't work the same way.

On Sunday, June 9, 2013, Morgan Packard wrote:

My bad, I think. Looks like I was working off the master branch, which doesn't yet use smart pointers for synths, right?

On Sat, Jun 8, 2013 at 11:02 PM, Nick D. <notifications@github.com<javascript:_e({}, 'cvml', 'notifications@github.com');>> wrote:

Weird, that is basically exactly what the synthfactory openframeworks demo does, and last I checked that was working fine (a few days ago). I will have a look soon.

On Saturday, June 8, 2013, Morgan Packard wrote:

I've just tried to do the following:

create an openFrameworks project, with a Synth member variable.

In setup, I assign a Synth subclass to the member variable. So like this:

// class member vars ... Synth synth

// in setup synth = SynthSubclass()

Works fine if I just do this:

// class member vars ... SynthSubclass synth

on first glance, looks like BufferFiller's bufferReadPosition_ position gets all out of whack (I was seeing huge values for it).

Obivously this isn't enough info to fix the problem. I want to do some fun coding right now and don't want to stop to fully dig in to the bug. But something's definitely up, and it def. needs to be figured out.

— Reply to this email directly or view it on GitHub< https://github.com/TonicAudio/Tonic/issues/182> .

Nick Donaldson ndonald2@gmail.com <javascript:_e({}, 'cvml', 'ndonald2@gmail.com');>

— Reply to this email directly or view it on GitHub< https://github.com/TonicAudio/Tonic/issues/182#issuecomment-19159911> .

Morgan Packard cell: (720) 891-0122 aim: mpackardatwork twitter: @morganpackard

— Reply to this email directly or view it on GitHubhttps://github.com/TonicAudio/Tonic/issues/182#issuecomment-19167328 .

Nick Donaldson ndonald2@gmail.com

morganpackard commented 11 years ago

I think it's actually not the copy constructor it's that the subclass part of the object gets sliced off when assigning it to a non-pointer variable of the superclass type.

Sent from my iPhone

On Jun 9, 2013, at 11:18 AM, "Nick D." notifications@github.com wrote:

Right, that makes more sense. The implicit copy constructor on master won't work the same way.

On Sunday, June 9, 2013, Morgan Packard wrote:

My bad, I think. Looks like I was working off the master branch, which doesn't yet use smart pointers for synths, right?

On Sat, Jun 8, 2013 at 11:02 PM, Nick D. <notifications@github.com<javascript:_e({}, 'cvml', 'notifications@github.com');>> wrote:

Weird, that is basically exactly what the synthfactory openframeworks demo does, and last I checked that was working fine (a few days ago). I will have a look soon.

On Saturday, June 8, 2013, Morgan Packard wrote:

I've just tried to do the following:

create an openFrameworks project, with a Synth member variable.

In setup, I assign a Synth subclass to the member variable. So like this:

// class member vars ... Synth synth

// in setup synth = SynthSubclass()

Works fine if I just do this:

// class member vars ... SynthSubclass synth

on first glance, looks like BufferFiller's bufferReadPosition_ position gets all out of whack (I was seeing huge values for it).

Obivously this isn't enough info to fix the problem. I want to do some fun coding right now and don't want to stop to fully dig in to the bug. But something's definitely up, and it def. needs to be figured out.

— Reply to this email directly or view it on GitHub< https://github.com/TonicAudio/Tonic/issues/182> .

Nick Donaldson ndonald2@gmail.com <javascript:_e({}, 'cvml', 'ndonald2@gmail.com');>

— Reply to this email directly or view it on GitHub< https://github.com/TonicAudio/Tonic/issues/182#issuecomment-19159911> .

Morgan Packard cell: (720) 891-0122 aim: mpackardatwork twitter: @morganpackard

— Reply to this email directly or view it on GitHub< https://github.com/TonicAudio/Tonic/issues/182#issuecomment-19167328> .

Nick Donaldson ndonald2@gmail.com

— Reply to this email directly or view it on GitHubhttps://github.com/TonicAudio/Tonic/issues/182#issuecomment-19167773 .

morganpackard commented 11 years ago

Actually, not sure that makes sense. Not exactly sure why it didn't work. But.. . whatever. Mystery solved enough.

Sent from my iPhone

On Jun 9, 2013, at 11:18 AM, "Nick D." notifications@github.com wrote:

Right, that makes more sense. The implicit copy constructor on master won't work the same way.

On Sunday, June 9, 2013, Morgan Packard wrote:

My bad, I think. Looks like I was working off the master branch, which doesn't yet use smart pointers for synths, right?

On Sat, Jun 8, 2013 at 11:02 PM, Nick D. <notifications@github.com<javascript:_e({}, 'cvml', 'notifications@github.com');>> wrote:

Weird, that is basically exactly what the synthfactory openframeworks demo does, and last I checked that was working fine (a few days ago). I will have a look soon.

On Saturday, June 8, 2013, Morgan Packard wrote:

I've just tried to do the following:

create an openFrameworks project, with a Synth member variable.

In setup, I assign a Synth subclass to the member variable. So like this:

// class member vars ... Synth synth

// in setup synth = SynthSubclass()

Works fine if I just do this:

// class member vars ... SynthSubclass synth

on first glance, looks like BufferFiller's bufferReadPosition_ position gets all out of whack (I was seeing huge values for it).

Obivously this isn't enough info to fix the problem. I want to do some fun coding right now and don't want to stop to fully dig in to the bug. But something's definitely up, and it def. needs to be figured out.

— Reply to this email directly or view it on GitHub< https://github.com/TonicAudio/Tonic/issues/182> .

Nick Donaldson ndonald2@gmail.com <javascript:_e({}, 'cvml', 'ndonald2@gmail.com');>

— Reply to this email directly or view it on GitHub< https://github.com/TonicAudio/Tonic/issues/182#issuecomment-19159911> .

Morgan Packard cell: (720) 891-0122 aim: mpackardatwork twitter: @morganpackard

— Reply to this email directly or view it on GitHub< https://github.com/TonicAudio/Tonic/issues/182#issuecomment-19167328> .

Nick Donaldson ndonald2@gmail.com

— Reply to this email directly or view it on GitHubhttps://github.com/TonicAudio/Tonic/issues/182#issuecomment-19167773 .