Updating an old prok=ject

I have an old project that was created originally with the Introjucer, but has been managed manually so the introjuect project is not longer useful. But I need to get to a newer version of juce.

I tried to just copy in the modules. That causes millions of errors. I now have resolved half a million of them but it would be nice if I could some how build it with a projucer project. I know very little about the projucer.

Anyone out there have experience in creating an introjucer project with an already existing windows project?

It shouldn’t be too complicated unless you have a lot of other libraries aside from JUCE you’re linking to?

You’ll need to share more details about what makes your project difficult to build and for most things there are fields for these options in projucer

The method I used above actually worked pretty well. The ‘millions of errors’ is down below 100 after some minor changes. But big obstacle I am facing now is the use of unique_ptr. I think I need a real c++ expert to help be with this.

I had a class I called IdShapeButton. A button derived from DrawableButton and adds button info fields for usage of the button like channel number, usage type(mute/solo/…) among other things. (Note:only relevant code shown)

class IdShapeButton : public DrawableButton
	IdShapeButton(const String& name, Drawable *off, Drawable *over, Drawable *on, Drawable *overon);

cpp code:

IdShapeButton::IdShapeButton(const String& name, Drawable *Off, Drawable *Over, Drawable *On, Drawable *OverOn): DrawableButton(name, ImageStretched) //ImageButton(name)
	setImages(Off,OverOn,On, nullptr, On, Over, On);

The call to it is like this:

File Mon(g_cCurrentPath + g_Button_On[MUTE_Button]);
Drawable * ButtonOnDrw = Drawable::createFromImageFile(Mon);

mute[channel] = new IdShapeButton("Mute", ButtonOnDrw, ButtonOverDrw, ButtonOffDrw, ButtonOvrOnDrw);

The problem is that now createFromImageFile now returns static std::unique_ptr< Drawable>

I use the drawable images for many(hundreds) of buttons so I dont want a separate copy of the images for every button. I use the same images for all the buttons.

This unique_ptr is new to me. How should this be implemented/changed?

The documentation for DrawableButton::setImages says:

The button will keep its own internal copies of these drawables.

So you always dealt with hundreds of copies in your old code anyway :wink: If this has not been an issue before, it won’t be now.

Regarding the changes towards std::unique_ptr: The old API expected that you deleted the returned drawable manually after using it, I expect that you have a delete ButtonOnDrw somewhere after the code where you created all your buttons. std::unique_ptr now takes care of memory management so that you simply cannot forget delete calls on pointers (which creates memory leaks) but automatically deletes the pointed to object as soon as it goes out of scope. Before std::unique_ptr was used as a de-facto standard in modern C++, JUCE already had the ScopedPointer class that basically did the same (but is now deprecated in favour of std::unique_ptr).

To retrieve the underlying raw pointer from a unique ptr, there is the get function. You could rework your code like that:

IdShapeButton::IdShapeButton (const String& name, std::unique_ptr<Drawable>& Off, std::unique_ptr<Drawable>& Over, std::unique_ptr<Drawable>& On, std::unique_ptr<Drawable>& OverOn): DrawableButton (name, ImageStretched)
	setImages (Off.get(), OverOn.get(), On.get(), nullptr, On.get(), Over.get(), On.get());

auto ButtonOnDrw = Drawable::createFromImageFile(Mon);

mute[channel] = new IdShapeButton("Mute", ButtonOnDrw, ButtonOverDrw, ButtonOffDrw, ButtonOvrOnDrw);

Note that I used auto here, which avoids long typenames – a style that is especially beneficial when a lot of unique ptrs are used, as they create quite long typenames :wink:

Sidenote: Since you are allocating the buttons themselves also via new, you might also want to brush up that code to follow modern C++ patterns use unique ptrs (which of course requires that the container you are assigning the pointer to is suitable to unique pointers) e.g. like

mute[channel] = std::make_unique<IdShapeButton> ("Mute", ButtonOnDrw, ButtonOverDrw, ButtonOffDrw, ButtonOvrOnDrw);

This will avoid a lot of delete calls in your destructors. But of course, your first aim is to get your project compiling at all :wink:

Thank you. I tried several ways to fix this (not really understanding it) including this. But I couldn’t get it to compile and the errors VS where no help. But you sample showed me my error, I was missing ‘&’.

I am down to 1 error I don’t understand

VS says:
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\assert.h(18,1): error C2144: syntax error: ‘int’ should be preceded by ‘;’ (compiling source file …\Source\Compressor.cpp)

The line in error is:

The macro is defined as this found in vcruntime.h:

#define _CRT_BEGIN_C_HEADER            \
        __pragma(pack(push, _CRT_PACKING)) \
        extern "C" {

    #define _CRT_END_C_HEADER \
        }                     \

Why would a windows header file be giving me this error?

I finally found the problem. I was missing a ‘;’ after a “using namespace juce”. Amazing how hard it wast to find. Everything is building now but the number changes I had to make to get it to build was huge.
I did this update to fix a problem with touch screen and all is well now so it was worth it.