COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 08-11-2011, 07:50 PM   #1
HoRNet
Human being with feelings
 
Join Date: Feb 2011
Posts: 128
Default IGraphic resize on OSX (wdl-ce)

Hi, I searched the forum but I haven't been able to find any thread about multi size GUIs.

I need to develop a plugin wich can display itself using different sizes for the gui, i don't neet a completely resizable gui, just a switch that doubles the plugin editor for example.

I've seen that IGraphics::Resize method, but at least on mac it doesn't seems to work. The code is there but i think (from what i understand from the carbon docs) it's wrong in the carbon implementation, and while the cocoa seems right, my test plugin crashes reaper64.

In carbon there is a call to HIViewSetFrame inside the IGraphicCarbon class that, from what i understand, is run in the graphic thread, now the carbon docs states that that method is not thread safe and should be only be called from main thread, so it should be the host that owns the window the one who calls the resize, in fact the crash occurs occasionally and, looking to the crash report, always inside some apple stuff, never in the same spot.

The problem is i really don't know how to fix it, how does VSTGUI deal with it for example? i've had a look at the code and it doesn't seems different from the IPlug implementation, so must be something els in IPlug that i ignore...

Regarding cocoa, if i draw an empty frame (just attach graphic and then resize) it works fine, i can resize the frame as much as i want, if then i attach a control, simply subclassing IControl and drawing a black rectangle in the Draw method, reaper64 crashes in the draw method of the subclassed IControl, and i have yet to investigate the reason...

Now this long post comes to an end, has anybody successfully done a resizable gui with IPlug?
HoRNet is offline   Reply With Quote
Old 08-12-2011, 07:52 AM   #2
olilarkin
Human being with feelings
 
olilarkin's Avatar
 
Join Date: Apr 2009
Location: York, UK
Posts: 794
Default

i never tried this and i'm not aware of any iPlug plugins that do it. It seems like it would probably be a real PITA to support this feature too, since it's not officially supported by vst2 (not sure about au) and it will likely not work in all hosts. It might be an idea, rather than dynamically resizing, you could let the user store the dimensions in a text file that gets read when the plugin loads.

FWIW, i think when you read "main" thread in this context it is the same thing as the "graphics thread"... i.e. not a high-priority audio thread.
__________________
VirtualCZ | pMix | Endless Series | WDL-OL Plugin dev framework
Available for consultancy/tuition via Skype (help with IPlug/JUCE/MaxMSP)
olilarkin is offline   Reply With Quote
Old 08-12-2011, 08:12 AM   #3
HoRNet
Human being with feelings
 
Join Date: Feb 2011
Posts: 128
Default

well, i know is not supported by the VST spec, but VSTGUI has the resize code in it and i've found this link:

http://www.oifii.org/ns-org/nsd/ar/c...maceditor.html

that states this:

Code:
Resizing the Plug-In

If you want to resize your view, just do it, but don't resize the host window.
HIRect pluginBounds;
HIViewGetFrame (myPluginView, &pluginBounds);
pluginBounds.size.width = newWidth;
pluginBounds.size.height = newHeight;
HIViewSetFrame (myPluginView, &pluginBounds);
The host needs to listen to bounds changes on the Plug-In view and resize its window accordingly.
that is very similar to the code found in IPlug in IGraphicsCarbon, but ever replacing the code with the above one i still get the crashes (tested in Ableton Live 7 BTW).

Regarding the "main thread" argument the fact that:

Code:
The host needs to listen to bounds changes on the Plug-In view and resize its window accordingly.
make me think that the host owns the thread that should do the resize, how plugins like Reaktor handles this since the gui is resizable...

I've read on KVR tips on creating a child window in the main window provided by the host so that the process is completely owned by the plugin and you can do whatever you want with your window, but it seems more complicated and a lot of code (that may fail) to manage...
HoRNet is offline   Reply With Quote
Old 08-12-2011, 04:50 PM   #4
olilarkin
Human being with feelings
 
olilarkin's Avatar
 
Join Date: Apr 2009
Location: York, UK
Posts: 794
Default

hmmm,

i tried it, and it crashed live 8 (carbon) and reaper (cocoa). I think this is some code that schwa didn't fully implement. It isn't implemented at all for AudioUnits.

I made some progress though...

first i checked IGraphics::Resize() and saw this:

Code:
void IGraphics::Resize(int w, int h)
{
  // The OS implementation class has to do all the work, then call up to here. ...
so i hade a look at IGraphicsMac and noticed that in fact IGraphics::Resize() was being called before the OS implementation did any work. So i hacked it, and now it doesn't crash and does resize the window in reaper and live. IGraphics::Resize() deletes the plugin's controls, which left me with a blank window - i commented this out and added a SetAllControlsDirty().

Code:
void IGraphicsMac::Resize(int w, int h)
{
// was here
  if (mDrawBitmap) {
    mDrawBitmap->resize(w, h);
  } 
  
#ifndef IPLUG_NO_CARBON_SUPPORT
  if (mGraphicsCarbon) {
    mGraphicsCarbon->Resize(w, h);
  }
  else
#endif
  if (mGraphicsCocoa) {
    NSSize size = { w, h };
    [(IGRAPHICS_COCOA*) mGraphicsCocoa setFrameSize: size ];
  }
  
  IGraphics::Resize(w, h); // < - this was at the top of the method
}
Code:
void IGraphics::Resize(int w, int h)
{
  // The OS implementation class has to do all the work, then call up to here.
  mWidth = w;
  mHeight = h;
  ReleaseMouseCapture();
  //mControls.Empty(true);
  mPlug->ResizeGraphics(w, h);
  SetAllControlsDirty();
}
This needs a bit of thought though because at the moment I am just testing with a simple small->bigger gui. If it goes the other way i guess there might be problems with the way i have hacked it. In which case maybe its good to recreate the entire gui, which is what was maybe intended by calling mControls.Empty(true); ... but i couldn't see how they would be created again... I guess it should be up to the programmer - in which case maybe we need a virtual IPlugBase method that triggers when a resize occurs... or something like that .

Also I noticed IGraphicsWin::Resize calls IGraphics::Resize(w, h); straight away too... i wonder if it's working on windows?
__________________
VirtualCZ | pMix | Endless Series | WDL-OL Plugin dev framework
Available for consultancy/tuition via Skype (help with IPlug/JUCE/MaxMSP)

Last edited by olilarkin; 08-12-2011 at 04:55 PM.
olilarkin is offline   Reply With Quote
Old 08-12-2011, 05:52 PM   #5
HoRNet
Human being with feelings
 
Join Date: Feb 2011
Posts: 128
Default

Quote:
Originally Posted by olilarkin View Post
hmmm,

i tried it, and it crashed live 8 (carbon) and reaper (cocoa). I think this is some code that schwa didn't fully implement. It isn't implemented at all for AudioUnits.

I made some progress though...

first i checked IGraphics::Resize() and saw this:

Code:
void IGraphics::Resize(int w, int h)
{
  // The OS implementation class has to do all the work, then call up to here. ...
so i hade a look at IGraphicsMac and noticed that in fact IGraphics::Resize() was being called before the OS implementation did any work. So i hacked it, and now it doesn't crash and does resize the window in reaper and live. IGraphics::Resize() deletes the plugin's controls, which left me with a blank window - i commented this out and added a SetAllControlsDirty().

Code:
void IGraphicsMac::Resize(int w, int h)
{
// was here
  if (mDrawBitmap) {
    mDrawBitmap->resize(w, h);
  } 
  
#ifndef IPLUG_NO_CARBON_SUPPORT
  if (mGraphicsCarbon) {
    mGraphicsCarbon->Resize(w, h);
  }
  else
#endif
  if (mGraphicsCocoa) {
    NSSize size = { w, h };
    [(IGRAPHICS_COCOA*) mGraphicsCocoa setFrameSize: size ];
  }
  
  IGraphics::Resize(w, h); // < - this was at the top of the method
}
Code:
void IGraphics::Resize(int w, int h)
{
  // The OS implementation class has to do all the work, then call up to here.
  mWidth = w;
  mHeight = h;
  ReleaseMouseCapture();
  //mControls.Empty(true);
  mPlug->ResizeGraphics(w, h);
  SetAllControlsDirty();
}
This needs a bit of thought though because at the moment I am just testing with a simple small->bigger gui. If it goes the other way i guess there might be problems with the way i have hacked it. In which case maybe its good to recreate the entire gui, which is what was maybe intended by calling mControls.Empty(true); ... but i couldn't see how they would be created again... I guess it should be up to the programmer - in which case maybe we need a virtual IPlugBase method that triggers when a resize occurs... or something like that .

Also I noticed IGraphicsWin::Resize calls IGraphics::Resize(w, h); straight away too... i wonder if it's working on windows?
well i'm gonna try your code and see if it works, i havent thought about moving that resize down below...i feel really dumb i spent about two days in my spare time trying to figure out what was happening, and lost myself in threads and carbon, the funny thing is that i wasn't getting any crash in reaper64 in the resize if the gui was empty (no icontrols attached)

but anyway thank you for your time, i'm gonna dig a little deeper in the issue (i haven't tested the windows version yet) and after all is ready try to put those changes back in to the wdl-ce (if it's still alive )

Thank you again for your help
Saverio
HoRNet is offline   Reply With Quote
Old 08-14-2011, 03:20 AM   #6
cerberus
Human being with feelings
 
Join Date: Nov 2009
Location: memory
Posts: 628
Default

it seems that IGraphics::Resize() (or something similar) is used in schwa's "olga" synth.
cerberus is offline   Reply With Quote
Old 08-14-2011, 10:06 AM   #7
olilarkin
Human being with feelings
 
olilarkin's Avatar
 
Join Date: Apr 2009
Location: York, UK
Posts: 794
Default

hmm, just tried olga, and the graphics resizing doesn't seem to work in any osx host i tried... it doesn't crash but the gui graphics get corrupted. Not sure if it is IPlug or not
__________________
VirtualCZ | pMix | Endless Series | WDL-OL Plugin dev framework
Available for consultancy/tuition via Skype (help with IPlug/JUCE/MaxMSP)
olilarkin is offline   Reply With Quote
Old 02-15-2012, 02:39 PM   #8
olilarkin
Human being with feelings
 
olilarkin's Avatar
 
Join Date: Apr 2009
Location: York, UK
Posts: 794
Default

fixed!

can't work out how to embed the gif!
Attached Images
File Type: gif resize.gif (39.7 KB, 98 views)
__________________
VirtualCZ | pMix | Endless Series | WDL-OL Plugin dev framework
Available for consultancy/tuition via Skype (help with IPlug/JUCE/MaxMSP)

Last edited by olilarkin; 02-15-2012 at 02:49 PM.
olilarkin is offline   Reply With Quote
Old 02-15-2012, 03:05 PM   #9
HoRNet
Human being with feelings
 
Join Date: Feb 2011
Posts: 128
Default

i'm glad you fixed it!

i've left the project on which i was working alone for a while (but i plan of finishing it sooner or later), if i remember well i was able to find a way to resize the gui reliably on osx, and was planning to give it back wo the wdl-ce, how did you fixed it?

i'll have a look to my old code and see how i didi it
HoRNet is offline   Reply With Quote
Old 02-15-2012, 03:38 PM   #10
HoRNet
Human being with feelings
 
Join Date: Feb 2011
Posts: 128
Default

ok i opened my old project, and i remembered what my problem was.

when i scale the gui to make it larger everything is ok, when i scale it back everything gets zoomed out, not only the gui container gets scaled, but the controls too, but only on carbon hosts.

I stopped there

have you tried your fix in carbon hosts?
HoRNet is offline   Reply With Quote
Old 02-16-2012, 02:08 AM   #11
olilarkin
Human being with feelings
 
olilarkin's Avatar
 
Join Date: Apr 2009
Location: York, UK
Posts: 794
Default

yeah i have tried it in lots of hosts on osx and it's mostly working with AU,VST and Standalone (still working on VST3 and RTAS), although i think some hosts aren't listening properly to changes in the carbon view size, and don't adjust their windows accordingly.

I also noticed the zooming and changed this behaviour. The next version of wdl-ol will have these changes
__________________
VirtualCZ | pMix | Endless Series | WDL-OL Plugin dev framework
Available for consultancy/tuition via Skype (help with IPlug/JUCE/MaxMSP)
olilarkin is offline   Reply With Quote
Old 05-14-2012, 10:54 AM   #12
nicknick
Human being with feelings
 
Join Date: May 2012
Posts: 1
Default

Quote:
Originally Posted by olilarkin View Post
fixed!
can you specify what was the fix? (giving a link for git commit would be enough).
we're also having problem of white background being left after we make our UI smaller. (using carbon / Qt)
nicknick is offline   Reply With Quote
Old 05-14-2012, 11:39 AM   #13
olilarkin
Human being with feelings
 
olilarkin's Avatar
 
Join Date: Apr 2009
Location: York, UK
Posts: 794
Default

if you look at IGraphicsCarbon.cpp - IGraphicsCarbon::Resize(int w, int h) you will find the platform specific code for GUI resizing, I'm not sure how this relates to what you do with frameworks other than IPlug.

https://github.com/olilarkin/wdl-ol/...hicsCarbon.cpp

Also the VSTGUI mailing list has some clues about this stuff I think.
__________________
VirtualCZ | pMix | Endless Series | WDL-OL Plugin dev framework
Available for consultancy/tuition via Skype (help with IPlug/JUCE/MaxMSP)
olilarkin is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:53 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.