Releasing a small Sample Recording Plugin/App source for free

Wusik SP22 - Free & Open-Source Sample Recording Plugin/App

Source Code

Cheers, WilliamK


question on this:

static void stripSquare(juce::Image original, juce::Image destination[9], int height = 0, int offsetY = 0)

are you relying on the fact that juce::Image's internal object is reference-counted to get away with not passing that destination array by reference?

Also, it’s just purely a style choice, but why not pass std::array<juce::Image, 9> instead? std::array<> is a cost-free wrapper around raw arrays…

Oh, thanks, did not know about that. Learning something new. :slight_smile:

Cheers, WilliamK

Always interesting to read other peoples code :slight_smile:

But I can never get over questions about how people format their code and look just at what it does. I’m reading this and thinking, “I wonder why William uses comment characters on every blank line”, and not really taking in what it’s actually doing at all!!

Maybe I’ve had too much coffee and not enough food though!


In C/C++ juce::Image destination[9] does not mean much else than “juce::Image* destination”. So he really is passing a pointer to the first image with a little hint, that there are nine images in total at this address.

Note, that the following compiles without warnings or errors:

void f(int a[6]){}

int main()
	int a;

	int b[2];

	int c[20];

	return 0;

crazy, eh ?

Edited: six => nine

Not crazy at all because there is no bounds checking in C/C++ and never was.

That’s why I recommended that he use std::array<Image, 9>. if he does that, the type system will ensure he passes the correct object type.

1 Like

I was answering your question:

Plain old c-arrays are not passed by value (like you presumably thought) - but are decaying into a pointer - There is no point in passing the array by reference.

@MBO: My point was, that IMHO it’s a reasonable assumption, that the size of the array is part of the type - and thus the C++ type system would be kicking in when there’s an obvious mistake like this - but it’s not. This is more about the C++ type system (compile time) than it is about bounds checking (runtime).

PS.: @WilliamkWusik: thanks for sharing!
PPS: I would probably have used a std::array as well - and passed it by reference.

1 Like

ahh you’re right. my fault.

‘void WusikPinkImage::stripSquare(juce::Image &,std::arrayjuce::Image,9,int,int)’: cannot convert argument 2 from ‘juce::Image [9]’ to ‘std::arrayjuce::Image,9

While using juce juce::Image* works great.

Well, I guess I could just change the declaration of background. :wink:

Hummm, it no longer works now. As it’s no longer a pointer to the output image. Bummer…

I always think that the simplest solutions are the best. I never used std::array as I try to keep all the code JUCE based. Is silly, but is just how my brain works…

Some people also mentioned that I add // to every blank line, is severe OCD to be honest. I’m bipolar with some other problems, so coding is always a challenge. :wink:

you want this:

static void stripSquare(juce::Image original, 
                        std::array<juce::Image, 9>& destination, 
                        int height = 0, 
                        int offsetY = 0);

the Standard Library containers are used throughout JUCE. you should learn to use std::vector, std::array, std::map, etc… JUCE is even replacing a lot of their internal containers with the STL containers.

1 Like

Ok, but they look ultra ugly to me. :-p I’m old… learning new stuff is hard sometimes…

Now it’s working correctly. I did try with & before but was getting an error and was tired to look what it was. Turns out I forgot to put include in the editor definition.

static void stripSquare(Image& original, std::array<Image, 9>& destination, int height = 0, int offsetY = 0)

Now it works correctly. I will update the GitHub area right after this message.

Thanks again for showing me the way. I have my problems but I always try to learn things when possible. :slight_smile:


1 Like

Here’s the official page for Wusik SP22, the sampler plugin/app. Includes the new OSX version, the Windows version, Manual and Source-Code.