Accessing the name text of a sampler sound object


#1

I need to chuck some conditionals against the samplersounds I have loaded since I have assigned multiple per note, so I’m going to use the name of the samplersound object to try ascertain which one needs to be sent to the voice in noteOn()

When I chuck a breakpoint in there and inspect the sound object, this is what it looks like in my watch:

I can see the text is in there which I need to access, but when I try access it with sound.name.text I get the output class “juce::SynthesiserSound” has no member “name”

I found that SamplerSound should have a getName() member function but I also get the same output when I try run sound.getName()


#2

It’s hard tp help without seeing more of the code.


#3

At this point I haven’t made any modifications, this is in the standard noteOn() function in juce_Synthesiser.cpp


#4

Are you confusing SynthesiserSound and SamplerSound?

I see no variable named name in SynthesiserSound.

Rail


#5

The “name” I’m trying to access appears to belong to SamplerSound when I inspect the “sound” object in my watch


#6

Synthesizer is using a SynthesiserSound object… subclass it and add your own name member.

Rail


#7

But I can see that the “sound” object has the variable I need in the watch at the point where I need it. I just have no clue how to access it


#8

What kind of object is sound? It seems odd that it’s a SamplerSound object. Did you cast it? If you want it to be a SamplerSound then dynamic cast it I guess.

Rail


#9

I haven’t touched the noteOn function yet, I just copied it into my subclass so I can make the modifications I need to make.

You’re right, it does seem to be synthesisersound SynthesiserSound* const sound = sounds.getUnchecked(i); however it definitely contains the name variable! You can see it in the screenshot I included


#10

The compiler thinks it’s a SynthesiserSound object

Rail


#11

Just a general side note, if you come into threading issues (and this is a class that has the potential, since loading and bank switching etc. is issued from the message thread, if it is result of a GUI action), using a name is an awful choice, since it is the least atomic changeable variable type.

Strings are for humans, computers don’t like strings.

Floats and doubles are also bad (just for completeness).
Ideally use an integer or the pointer to the object you are referring to, if you can manage the data structures and ownerships properly.


#12

@Rail_Jon_Rogut when I try cast it as SamplerSound instead I get the following error: no suitable conversion function from "juce::ReferenceCountedObjectPtr<juce::SynthesiserSound>" to "juce::SamplerSound *const" exists