How to easily use png from knobman in my code?


#1

Hi,
I guess I asked too confused or global question in another thread so I want to cut the problem into pieces (even if I’d need to understand the thing more globally, even at this point)

So, I have my png coming from Knobman, containing all the 32 states of my rotary knob.

I want to integrate it in my Juce C++ audio plugin source.

What is the workflow to do that, using the Jucer ?


#2

OK, basically to get this to work you need to create a new class inheriting from slider which can take an image and use that to paint the slider rather than the default look and feel.

I quickly knocked this up from some old code I had lying around. It is very rough but covers a lot of the questions you have been asking recently so thought it might help others. Just download the zip, open the Introjucer project to set up your juce location and then open the project, build and run.

Steps taken:

  1. Open the Introjucer and create a new project
  2. Add new files for MainComponent and FilmstripSlider
  3. Add knob.jpg image (from Max/MSP) to project (automatically gets added as binary data)
  4. Create FilmstripSlider class inheriting from Slider and overriding paint method
  5. Load image into slider from binary data (MainComponent.cpp line 15)

Hope this explains things clearly.

P.S. I had to make the image very low quality to attach here, obviously this can be replaced with any image.


#3

thanks a lot !
aggregating all your precious informations to make my own GUI workflow

with yours and anima’s one (http://rawmaterialsoftware.com/viewtopic.php?f=7&t=7881) I’d be ok in a few hours I HOPE :slight_smile:

your way is very nice, and I now need to figure out how to combine the two tips:

  • using knobman with the juce (yours, amazing and correctly built here… still studying it)
  • using the jucer to include/join knobman stuff too

basically, I miss something, but I’m near, I hope :slight_smile:


#4

Ok, I actually thought you might say that so I’ve just done another version which uses a Jucer generated main component (called the default “NewJucerComponent”) and used that to show the interface instead. Download the new project and you should see what I mean (look at line 29 in MainAppWindow.cpp). Now you can open up “NewJucerComponent.cpp” in the Jucer and edit it, it will preserve all the things between the [] brackets that I had to add to make it functional.

One thing to note is that the Jucer is pretty old now and uses an older style of coding that Jules is moving away from ie. the T() macro, heap components and member listener classes. So you may get some warnings about depreciated stuff when using this version.

I personally don’t really use the old Jucer, Juce is written so well that it takes practically as long to type the layout of some components as it does to set their properties in the Jucer. Positioning is also more flexible when you custom type it and you are in complete control of the code order so it becomes more readable (IMO).

Personally I only really use the Jucer for complex graphics and paths. I then just copy the code out and put it in my own files. I know others on her use it more though and if it works for you then great!

Hope that explains things a bit better.


#5

testing it right now.

I wanted to thank you a lot.
I’m happy about your help because it had & will unstick me and I could go further


#6

I have some very little problem with the size of each part.
I tried to move them a bit, resize them.

as you explained well, I had to modify some little part inside the “the jucer’s tags” in order to update that

digging …


#7

it is ok with graphics part.
I know how to move, resize etc.

BIG THANKS.

next step, succeeding in compiling the SAME stuff as an audio plugin.
now an error.
I thought if I would put auio plugin in introjucer, it would have add stuff in my files… (maybe because filenames are different of pluginEditor etc etc)


#8

You have a linker error. Looks like your project doesn’t link to the VST libraries?

Bruce


#9

Hi Bruce.
They are linked.
Rechecking but…


#10

here is the project.
[attachment=1]FilmstripSliderAsAPlugin.zip[/attachment]

as I wrote, I took the one by dave96. It worked.
I changed some UI stuff, place etc. it worked.

I opened the .jucer file with introjucer in order to change the project from Applications to Audio Plugin, save & open with Xcode.

And here is the error.
I rechecked, libs are correctly linked no?

[attachment=0]Capture d’écran 2011-09-22 à 21.19.28.png[/attachment]


#11

No, it doesn’t look like you have VST libs in there. You have the Juce VST wrappers, but they require the actual VST libs.

I don’t use VST, but it’s a C++ thing. You might say it’s linked, your linker says it’s not.


#12

Ok
I don’t even know why:

if I create an audio plugin project from scratch with introjucer all works fine
and
if I take an existing application project, open it with introjucer, change it to audio plugin type, save it and open it, it doesn’t include VST libs …?!

I’ll dig that

thanks Bruce.


#13

That would probably qualify as an IntroJucer bug?


#14

not sure.
I retested the audio plugin demo, all inclusions seem to be the same.
I guess this is my definitions or I don’t know what in my code (I mean, not introjucer etc)


#15

looks like your project lacks a PluginProcessor.cpp file. Just switching the project type in the will change the build settings correctly, but it can’t convert your code.

You need AudioProcessor and AudioProcessorEditor subclasses (instead of the JUCEApplication an DocumentWindow subclasses) to actually make it a plugin. If you gather all your gui stuff in one Component, you can easily share that between a standalone and plugin project.


#16

[quote=“steffen”]looks like your project lacks a PluginProcessor.cpp file. Just switching the project type in the will change the build settings correctly, but it can’t convert your code.

You need AudioProcessor and AudioProcessorEditor subclasses (instead of the JUCEApplication an DocumentWindow subclasses) to actually make it a plugin. If you gather all your gui stuff in one Component, you can easily share that between a standalone and plugin project.[/quote]

especially for me, the simpler the better.

how could I gather all in one Component ?


#17

[code]void FilmstripSlider::paint(Graphics& g)
{
if (filmStripImage.isValid())
{
float fval = (getValue() - getMinimum()) / (getMaximum() - getMinimum()) * (numFrames - 1);
int value = (int)fval;

	int imageHeight; 
	int imageWidth;
    
	if (getTextBoxPosition() == TextBoxBelow)
    {
		imageWidth = getWidth() - getTextBoxHeight();
		imageHeight = getHeight() - getTextBoxHeight();
	}
	else
    {
		imageWidth = getWidth();
		imageHeight = getHeight();
	}
	
	if(isHorizontal)
    {
		float intpart = 0.f;
		float fractpart = modf(fval, &intpart);

		g.setOpacity(1.0f - fractpart);

		g.drawImage(filmStripImage, (getWidth() - imageWidth) * 0.5, 0, imageWidth, imageHeight,
					value * frameWidth, 0, frameWidth, frameHeight);

		g.setOpacity(fractpart);

		g.drawImage(filmStripImage, (getWidth() - imageWidth) * 0.5, 0, imageWidth, imageHeight,
					(value+1) * frameWidth, 0, frameWidth, frameHeight);
    }
	else
    {
		float intpart = 0.f;
		float fractpart = modf(fval, &intpart);

		g.setOpacity(1.0f - fractpart);

		g.drawImage(filmStripImage, 0, 0, imageWidth, imageHeight,
					0, value * frameHeight, frameWidth, frameHeight);

		g.setOpacity(fractpart);

		g.drawImage(filmStripImage, 0, 0, imageWidth, imageHeight,
					0, (value+1) * frameHeight, frameWidth, frameHeight);
    }
}

}[/code]

I would like to contribute a modification to the FilmStripSlider class posted above by Dave96
This will add motionblur to your frames rotation, works great using 32 frame tilesets. A little crude but it works :slight_smile:

About the modf()… you could value -= floor(value);


#18

as long as the frames of the JPG are horizontal then i can change knob.jpg to another file,,,

as i try to load a vertical image the program crash..

i tries setting the isHorisontal to false but it crash ... \

 

any idea ????

 

thanx