Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_TopicIcon
vector of delays
Avatar
Chris_1
Member
Members
October 26, 2019 - 1:37 pm
Member Since: September 29, 2019
Forum Posts: 4
sp_UserOfflineSmall Offline

I am trying to dynamically allocate the SimpleDelay object into a vector and am running into a lot of issues.  I need to create the SimpleDelay objects so that they are are not delete after the function they are created in finishes. 

I am defining the vector<SimpleDelay> object in the PluginCore class in plugincore.h then trying to allocate the SimpleDelay objects in the reset function in pluggincore.cpp using a for loop like:

In header plugincore

vector<SimpleDelay> delayVector; 

In reset()

for(int d= 0; d< nDelays; d++){

delayVector.emplace_back(new SimpleDelay);

}

With this I am getting this error on compile:

Severity Code Description Project File Line Suppression State
Error C2664 'SimpleDelay::SimpleDelay(const SimpleDelay &)': cannot convert argument 1 from 'SimpleDelay *' to 'const SimpleDelay &' TestFDN C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xmemory0 945

I originally tried using the push_back method, but ran into an issue that I was not pushing an address.  I think I may have a fundamental misunderstanding of how vectors work so any help would be greatly appreciated!   

Avatar
Tom
Admin
October 26, 2019 - 1:58 pm
Member Since: April 3, 2014
Forum Posts: 73
sp_UserOfflineSmall Offline

Hi Chris,

you declared a vector of "SimpleDelay", not a vector of "pointer to SimpleDelay".

 

For simplicity I would recommend to just resize the delayVector:

delayVector.resize(nDelays);

This will create the SimpleDelays directly "inside" the vector's memory and you don't have to care about deletion of the objects later.

Does the number of delays change at runtime? If not you could also consider using a fixed-size array (std::array) instead, probably of some kind of smart pointers.

 

Best Regards

Tom

Avatar
Chris_1
Member
Members
October 26, 2019 - 3:06 pm
Member Since: September 29, 2019
Forum Posts: 4
sp_UserOfflineSmall Offline

Hey Tom, 

Thank you for your help. 

I want to be able to resize the number of delays dynamically which is what is causing most of my problems.  I have been able to create similar hard-coded version of what I am working on, but they dynamic elements and memory management are causing me quite a bit of trouble here.  I do not intend for the plugin to resize whenever a parameter is changed, but rather when a flag from the GUI gets set.  (so it can be changed when it is bypassed or something).

I would like to create a wave-guide mesh algorithm that allows a user to change the alignment and number of scattering junctions.  I am planning on storing read and write delay indices within a scattering junction class that can be used to perform the scattering action every sample.    

Additionally, I tried to implement the resize method to the vector and I get a similar error.

Severity Code Description Project File Line Suppression State
Error C2280 'SimpleDelay::SimpleDelay(const SimpleDelay &)': attempting to reference a deleted function TestFDN C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xmemory0 945

Avatar
Tom
Admin
October 26, 2019 - 7:17 pm
Member Since: April 3, 2014
Forum Posts: 73
sp_UserOfflineSmall Offline

Hi Chris,

well - the compiler tells you the problem (in a seemingly cryptic way): SimpleDelay has no copy constructor, so it cannot be used as the value type in std::vector

You can use a vector of (smart-) pointers instead, e.g. std::vector<std::unique_ptr<SimpleDelay>>. 

But you may run into some troubles with your approach, because you cannot resize the delays while audio is processed. A UI-Flag typically will result in an "input event" which reaches your plugin processor in the "process" method, i.e. the audio thread, just like any other parameter change (in VST3 at least). Also, if you do it from a custom UI element which may not generate a parameter change but directly attempts to change your delays, the same problem persists: you cannot change anything the audio thread is currently using from the UI thread and the UI thread cannot know when this will be the case and has to assume that is it "always".

I would suggest to create the max number of SimpleDelay objects upfront and only "dynamically" use or not use them.

Forum Timezone: America/New_York

Most Users Ever Online: 78

Currently Online:
4 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Skyler: 48

Derek: 46

Frodson: 45

TheSmile: 43

Peter: 41

clau_ste: 39

JimmyM: 33

Gwen: 32

EZB: 24

lppier: 23

Member Stats:

Guest Posters: 1

Members: 575

Moderators: 1

Admins: 4

Forum Stats:

Groups: 12

Forums: 36

Topics: 593

Posts: 2366

Newest Members:

acv, Vasil992, Vasil92, dowsed, Simple, Chris_1, manyu, AdamR, Stuart, Al Calabrese

Moderators: W Pirkle: 358

Administrators: Tom: 73, JD Young: 80, Will Pirkle: 0, W Pirkle: 358