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: 171
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
 
Join Date: Apr 2009
Location: Berlin, Germany
Posts: 1,248
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 | Endless Series | iPlug2 | Linkedin | Facebook
olilarkin is offline   Reply With Quote
Old 08-12-2011, 08:12 AM   #3
HoRNet
Human being with feelings
 
Join Date: Feb 2011
Posts: 171
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
 
Join Date: Apr 2009
Location: Berlin, Germany
Posts: 1,248
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 | Endless Series | iPlug2 | Linkedin | Facebook

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: 171
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: 633
Default

it seems that IGraphics::Resize() (or something similar) is used in schwa's "olga" synth.
cerberus 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 07:49 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.