Browse Source

Use uint for sizes; Some DPF UI class changes and docs

gh-pages
falkTX 7 years ago
parent
commit
b9dcf5ca9f
18 changed files with 373 additions and 259 deletions
  1. +15
    -0
      dgl/Geometry.hpp
  2. +8
    -8
      dgl/Image.hpp
  3. +1
    -1
      dgl/ImageAboutWindow.hpp
  4. +4
    -4
      dgl/NanoVG.hpp
  5. +11
    -10
      dgl/Widget.hpp
  6. +3
    -3
      dgl/Window.hpp
  7. +18
    -0
      dgl/src/Geometry.cpp
  8. +9
    -9
      dgl/src/Image.cpp
  9. +1
    -1
      dgl/src/ImageAboutWindow.cpp
  10. +8
    -7
      dgl/src/NanoVG.cpp
  11. +35
    -34
      dgl/src/Widget.cpp
  12. +8
    -4
      dgl/src/Window.cpp
  13. +129
    -127
      distrho/DistrhoPlugin.hpp
  14. +106
    -32
      distrho/DistrhoUI.hpp
  15. +1
    -1
      distrho/src/DistrhoPluginJack.cpp
  16. +1
    -1
      distrho/src/DistrhoUI.cpp
  17. +14
    -16
      distrho/src/DistrhoUIInternal.hpp
  18. +1
    -1
      distrho/src/DistrhoUILV2.cpp

+ 15
- 0
dgl/Geometry.hpp View File

@@ -91,6 +91,11 @@ public:
*/
void moveBy(const Point<T>& pos) noexcept;

/**
Return true if point is (0, 0).
*/
bool isZero() const noexcept;

Point<T> operator+(const Point<T>& pos) noexcept;
Point<T> operator-(const Point<T>& pos) noexcept;
Point<T>& operator=(const Point<T>& pos) noexcept;
@@ -169,6 +174,16 @@ public:
*/
void shrinkBy(const T& divider) noexcept;

/**
Return true if size is null (0x0).
*/
bool isNull() const noexcept;

/**
Return true if size is not null (0x0).
*/
bool isNotNull() const noexcept;

Size<T> operator+(const Size<T>& size) noexcept;
Size<T> operator-(const Size<T>& size) noexcept;
Size<T>& operator=(const Size<T>& size) noexcept;


+ 8
- 8
dgl/Image.hpp View File

@@ -47,13 +47,13 @@ public:
Constructor using raw image data.
@note: @a rawData must remain valid for the lifetime of this Image.
*/
Image(const char* const rawData, const int width, const int height, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE);
Image(const char* const rawData, const uint width, const uint height, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE);

/**
Constructor using raw image data.
@note: @a rawData must remain valid for the lifetime of this Image.
*/
Image(const char* const rawData, const Size<int>& size, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE);
Image(const char* const rawData, const Size<uint>& size, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE);

/**
Constructor using another image data.
@@ -69,13 +69,13 @@ public:
Load image data from memory.
@note: @a rawData must remain valid for the lifetime of this Image.
*/
void loadFromMemory(const char* const rawData, const int width, const int height, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE) noexcept;
void loadFromMemory(const char* const rawData, const uint width, const uint height, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE) noexcept;

/**
Load image data from memory.
@note: @a rawData must remain valid for the lifetime of this Image.
*/
void loadFromMemory(const char* const rawData, const Size<int>& size, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE) noexcept;
void loadFromMemory(const char* const rawData, const Size<uint>& size, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE) noexcept;

/**
Check if this image is valid.
@@ -85,17 +85,17 @@ public:
/**
Get width.
*/
int getWidth() const noexcept;
uint getWidth() const noexcept;

/**
Get height.
*/
int getHeight() const noexcept;
uint getHeight() const noexcept;

/**
Get size.
*/
const Size<int>& getSize() const noexcept;
const Size<uint>& getSize() const noexcept;

/**
Get the raw image data.
@@ -133,7 +133,7 @@ public:

private:
const char* fRawData;
Size<int> fSize;
Size<uint> fSize;
GLenum fFormat;
GLenum fType;
GLuint fTextureId;


+ 1
- 1
dgl/ImageAboutWindow.hpp View File

@@ -38,7 +38,7 @@ protected:
void onDisplay() override;
bool onKeyboard(const KeyboardEvent&) override;
bool onMouse(const MouseEvent&) override;
void onReshape(int width, int height) override;
void onReshape(uint width, uint height) override;

private:
Image fImgBackground;


+ 4
- 4
dgl/NanoVG.hpp View File

@@ -45,7 +45,7 @@ public:
/**
Get size.
*/
Size<int> getSize() const noexcept;
Size<uint> getSize() const noexcept;

/**
Update image data.
@@ -62,7 +62,7 @@ protected:
private:
NVGcontext* fContext;
int fImageId;
Size<int> fSize;
Size<uint> fSize;
friend class NanoVG;

void _updateSize();
@@ -273,7 +273,7 @@ public:
Begin drawing a new frame.
@param withAlha Controls if drawing the shapes to the render target should be done using straight or pre-multiplied alpha.
*/
void beginFrame(const int width, const int height, const float scaleFactor = 1.0f, const Alpha alpha = PREMULTIPLIED_ALPHA);
void beginFrame(const uint width, const uint height, const float scaleFactor = 1.0f, const Alpha alpha = PREMULTIPLIED_ALPHA);

/**
Begin drawing a new frame inside a widget.
@@ -505,7 +505,7 @@ public:
/**
Creates image from specified image data.
*/
NanoImage* createImageRGBA(int w, int h, const uchar* data);
NanoImage* createImageRGBA(uint w, uint h, const uchar* data);

/* --------------------------------------------------------------------
* Paints */


+ 11
- 10
dgl/Widget.hpp View File

@@ -122,8 +122,8 @@ public:
@see onResize
*/
struct ResizeEvent {
Size<int> size;
Size<int> oldSize;
Size<uint> size;
Size<uint> oldSize;
};

/**
@@ -162,37 +162,37 @@ public:
/**
Get width.
*/
int getWidth() const noexcept;
uint getWidth() const noexcept;

/**
Get height.
*/
int getHeight() const noexcept;
uint getHeight() const noexcept;

/**
Get size.
*/
const Size<int>& getSize() const noexcept;
const Size<uint>& getSize() const noexcept;

/**
Set width.
*/
virtual void setWidth(int width) noexcept;
virtual void setWidth(uint width) noexcept;

/**
Set height.
*/
virtual void setHeight(int height) noexcept;
virtual void setHeight(uint height) noexcept;

/**
Set size using @a width and @a height values.
*/
virtual void setSize(int width, int height) noexcept;
virtual void setSize(uint width, uint height) noexcept;

/**
Set size.
*/
virtual void setSize(const Size<int>& size) noexcept;
virtual void setSize(const Size<uint>& size) noexcept;

/**
Get absolute X.
@@ -317,7 +317,8 @@ private:
bool fNeedsFullViewport;
bool fNeedsScaling;
bool fVisible;
Rectangle<int> fArea;
Point<int> fAbsolutePos;
Size<uint> fSize;

friend class CairoWidget;
friend class Window;


+ 3
- 3
dgl/Window.hpp View File

@@ -48,8 +48,8 @@ public:
bool isResizable() const noexcept;
void setResizable(bool yesNo);

int getWidth() const noexcept;
int getHeight() const noexcept;
uint getWidth() const noexcept;
uint getHeight() const noexcept;
Size<uint> getSize() const noexcept;
void setSize(uint width, uint height);
void setSize(Size<uint> size);
@@ -67,7 +67,7 @@ public:
protected:
virtual void onDisplayBefore();
virtual void onDisplayAfter();
virtual void onReshape(int width, int height);
virtual void onReshape(uint width, uint height);
virtual void onClose();

private:


+ 18
- 0
dgl/src/Geometry.cpp View File

@@ -90,6 +90,11 @@ void Point<T>::moveBy(const Point<T>& pos) noexcept
fY = static_cast<T>(fY+pos.fY);
}

template<typename T>
bool Point<T>::isZero() const noexcept
{
return fX == 0 && fY == 0;
}

template<typename T>
Point<T> Point<T>::operator+(const Point<T>& pos) noexcept
@@ -209,6 +214,19 @@ void Size<T>::shrinkBy(const T& divider) noexcept
fHeight = static_cast<T>(fHeight/divider);
}

template<typename T>
bool Size<T>::isNull() const noexcept
{
return fWidth == 0 && fHeight == 0;
}

template<typename T>
bool Size<T>::isNotNull() const noexcept
{
return fWidth != 0 || fHeight != 0;
}


template<typename T>
Size<T> Size<T>::operator+(const Size<T>& size) noexcept
{


+ 9
- 9
dgl/src/Image.cpp View File

@@ -31,7 +31,7 @@ Image::Image()
glGenTextures(1, &fTextureId);
}

Image::Image(const char* const rawData, const int width, const int height, const GLenum format, const GLenum type)
Image::Image(const char* const rawData, const uint width, const uint height, const GLenum format, const GLenum type)
: fRawData(rawData),
fSize(width, height),
fFormat(format),
@@ -42,7 +42,7 @@ Image::Image(const char* const rawData, const int width, const int height, const
glGenTextures(1, &fTextureId);
}

Image::Image(const char* const rawData, const Size<int>& size, const GLenum format, const GLenum type)
Image::Image(const char* const rawData, const Size<uint>& size, const GLenum format, const GLenum type)
: fRawData(rawData),
fSize(size),
fFormat(format),
@@ -73,12 +73,12 @@ Image::~Image()
}
}

void Image::loadFromMemory(const char* const rawData, const int width, const int height, const GLenum format, const GLenum type) noexcept
void Image::loadFromMemory(const char* const rawData, const uint width, const uint height, const GLenum format, const GLenum type) noexcept
{
loadFromMemory(rawData, Size<int>(width, height), format, type);
loadFromMemory(rawData, Size<uint>(width, height), format, type);
}

void Image::loadFromMemory(const char* const rawData, const Size<int>& size, const GLenum format, const GLenum type) noexcept
void Image::loadFromMemory(const char* const rawData, const Size<uint>& size, const GLenum format, const GLenum type) noexcept
{
fRawData = rawData;
fSize = size;
@@ -92,17 +92,17 @@ bool Image::isValid() const noexcept
return (fRawData != nullptr && fSize.getWidth() > 0 && fSize.getHeight() > 0);
}

int Image::getWidth() const noexcept
uint Image::getWidth() const noexcept
{
return fSize.getWidth();
}

int Image::getHeight() const noexcept
uint Image::getHeight() const noexcept
{
return fSize.getHeight();
}

const Size<int>& Image::getSize() const noexcept
const Size<uint>& Image::getSize() const noexcept
{
return fSize;
}
@@ -157,7 +157,7 @@ void Image::drawAt(const Point<int>& pos)
fIsReady = true;
}

Rectangle<int>(pos, fSize).draw();
Rectangle<int>(pos, fSize.getWidth(), fSize.getHeight()).draw();

glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);


+ 1
- 1
dgl/src/ImageAboutWindow.cpp View File

@@ -78,7 +78,7 @@ bool ImageAboutWindow::onMouse(const MouseEvent& ev)
return false;
}

void ImageAboutWindow::onReshape(int width, int height)
void ImageAboutWindow::onReshape(uint width, uint height)
{
Widget::setSize(width, height);
Window::onReshape(width, height);


+ 8
- 7
dgl/src/NanoVG.cpp View File

@@ -86,7 +86,7 @@ NanoImage::~NanoImage()
nvgDeleteImage(fContext, fImageId);
}

Size<int> NanoImage::getSize() const noexcept
Size<uint> NanoImage::getSize() const noexcept
{
return fSize;
}
@@ -107,8 +107,13 @@ void NanoImage::_updateSize()
int w=0, h=0;

if (fContext != nullptr && fImageId != 0)
{
nvgImageSize(fContext, fImageId, &w, &h);

if (w < 0) w = 0;
if (h < 0) h = 0;
}

fSize.setSize(w, h);
}

@@ -139,11 +144,9 @@ NanoVG::~NanoVG()

// -----------------------------------------------------------------------

void NanoVG::beginFrame(const int width, const int height, const float scaleFactor, const Alpha alpha)
void NanoVG::beginFrame(const uint width, const uint height, const float scaleFactor, const Alpha alpha)
{
if (fContext == nullptr) return;
DISTRHO_SAFE_ASSERT_RETURN(width > 0,);
DISTRHO_SAFE_ASSERT_RETURN(height > 0,);
DISTRHO_SAFE_ASSERT_RETURN(scaleFactor > 0.0f,);
DISTRHO_SAFE_ASSERT_RETURN(! fInFrame,);

@@ -419,11 +422,9 @@ NanoImage* NanoVG::createImageMem(uchar* data, int ndata)
return nullptr;
}

NanoImage* NanoVG::createImageRGBA(int w, int h, const uchar* data)
NanoImage* NanoVG::createImageRGBA(uint w, uint h, const uchar* data)
{
if (fContext == nullptr) return nullptr;
DISTRHO_SAFE_ASSERT_RETURN(w > 0, nullptr);
DISTRHO_SAFE_ASSERT_RETURN(h > 0, nullptr);
DISTRHO_SAFE_ASSERT_RETURN(data != nullptr, nullptr);

if (const int imageId = nvgCreateImageRGBA(fContext, w, h, data))


+ 35
- 34
dgl/src/Widget.cpp View File

@@ -27,7 +27,8 @@ Widget::Widget(Window& parent)
fNeedsFullViewport(false),
fNeedsScaling(false),
fVisible(true),
fArea(),
fAbsolutePos(0, 0),
fSize(0, 0),
leakDetector_Widget()
{
fParent._addWidget(this);
@@ -62,66 +63,66 @@ void Widget::hide()
setVisible(false);
}

int Widget::getWidth() const noexcept
uint Widget::getWidth() const noexcept
{
return fArea.getWidth();
return fSize.getWidth();
}

int Widget::getHeight() const noexcept
uint Widget::getHeight() const noexcept
{
return fArea.getHeight();
return fSize.getHeight();
}

const Size<int>& Widget::getSize() const noexcept
const Size<uint>& Widget::getSize() const noexcept
{
return fArea.getSize();
return fSize;
}

void Widget::setWidth(int width) noexcept
void Widget::setWidth(uint width) noexcept
{
if (fArea.getWidth() == width)
if (fSize.getWidth() == width)
return;

ResizeEvent ev;
ev.oldSize = fArea.getSize();
ev.size = Size<int>(width, fArea.getHeight());
ev.oldSize = fSize;
ev.size = Size<uint>(width, fSize.getHeight());

fArea.setWidth(width);
fSize.setWidth(width);
onResize(ev);

fParent.repaint();
}

void Widget::setHeight(int height) noexcept
void Widget::setHeight(uint height) noexcept
{
if (fArea.getHeight() == height)
if (fSize.getHeight() == height)
return;

ResizeEvent ev;
ev.oldSize = fArea.getSize();
ev.size = Size<int>(fArea.getWidth(), height);
ev.oldSize = fSize;
ev.size = Size<uint>(fSize.getWidth(), height);

fArea.setHeight(height);
fSize.setHeight(height);
onResize(ev);

fParent.repaint();
}

void Widget::setSize(int width, int height) noexcept
void Widget::setSize(uint width, uint height) noexcept
{
setSize(Size<int>(width, height));
setSize(Size<uint>(width, height));
}

void Widget::setSize(const Size<int>& size) noexcept
void Widget::setSize(const Size<uint>& size) noexcept
{
if (fArea.getSize() == size)
if (fSize == size)
return;

ResizeEvent ev;
ev.oldSize = fArea.getSize();
ev.size = size;
ev.oldSize = fSize;
ev.size = size;

fArea.setSize(size);
fSize = size;
onResize(ev);

fParent.repaint();
@@ -129,34 +130,34 @@ void Widget::setSize(const Size<int>& size) noexcept

int Widget::getAbsoluteX() const noexcept
{
return fArea.getX();
return fAbsolutePos.getX();
}

int Widget::getAbsoluteY() const noexcept
{
return fArea.getY();
return fAbsolutePos.getY();
}

const Point<int>& Widget::getAbsolutePos() const noexcept
{
return fArea.getPos();
return fAbsolutePos;
}

void Widget::setAbsoluteX(int x) noexcept
{
if (fArea.getX() == x)
if (fAbsolutePos.getX() == x)
return;

fArea.setX(x);
fAbsolutePos.setX(x);
fParent.repaint();
}

void Widget::setAbsoluteY(int y) noexcept
{
if (fArea.getY() == y)
if (fAbsolutePos.getY() == y)
return;

fArea.setY(y);
fAbsolutePos.setY(y);
fParent.repaint();
}

@@ -167,10 +168,10 @@ void Widget::setAbsolutePos(int x, int y) noexcept

void Widget::setAbsolutePos(const Point<int>& pos) noexcept
{
if (fArea.getPos() == pos)
if (fAbsolutePos == pos)
return;

fArea.setPos(pos);
fAbsolutePos = pos;
fParent.repaint();
}

@@ -186,7 +187,7 @@ Window& Widget::getParentWindow() const noexcept

bool Widget::contains(int x, int y) const noexcept
{
return (x >= 0 && y >= 0 && x < fArea.getWidth() && y < fArea.getHeight());
return (x >= 0 && y >= 0 && static_cast<uint>(x) < fSize.getWidth() && static_cast<uint>(y) < fSize.getHeight());
}

bool Widget::contains(const Point<int>& pos) const noexcept


+ 8
- 4
dgl/src/Window.cpp View File

@@ -580,7 +580,7 @@ struct Window::PrivateData {
// reset color
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

if (widget->fNeedsFullViewport || widget->fArea == Rectangle<int>(0, 0, fView->width, fView->height))
if (widget->fNeedsFullViewport || (widget->fAbsolutePos.isZero() && widget->fSize == Size<uint>(fView->width, fView->height)))
{
// full viewport size
glViewport(0, 0, fView->width, fView->height);
@@ -919,13 +919,17 @@ void Window::setResizable(bool yesNo)
pData->setResizable(yesNo);
}

int Window::getWidth() const noexcept
uint Window::getWidth() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(pData->fView->width >= 0, 0);

return pData->fView->width;
}

int Window::getHeight() const noexcept
uint Window::getHeight() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(pData->fView->height >= 0, 0);

return pData->fView->height;
}

@@ -1009,7 +1013,7 @@ void Window::onDisplayAfter()
{
}

void Window::onReshape(int width, int height)
void Window::onReshape(uint width, uint height)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


+ 129
- 127
distrho/DistrhoPlugin.hpp View File

@@ -407,207 +407,209 @@ struct TimePosition {
class Plugin
{
public:
/**
Plugin class constructor.
*/
/**
Plugin class constructor.
*/
Plugin(const uint32_t parameterCount, const uint32_t programCount, const uint32_t stateCount);

/**
Destructor.
*/
/**
Destructor.
*/
virtual ~Plugin();

/* --------------------------------------------------------------------------------------------------------
* Host state */
/* --------------------------------------------------------------------------------------------------------
* Host state */

/**
Get the current buffer size that will probably be used during processing, in frames.
This value will remain constant between activate and deactivate.
@note: This value is only a hint!
Hosts might call d_run() with a higher or lower number of frames.
@see d_bufferSizeChanged()
*/
/**
Get the current buffer size that will probably be used during processing, in frames.
This value will remain constant between activate and deactivate.
@note: This value is only a hint!
Hosts might call d_run() with a higher or lower number of frames.
@see d_bufferSizeChanged(uint32_t)
*/
uint32_t d_getBufferSize() const noexcept;

/**
Get the current sample rate that will be used during processing.
This value will remain constant between activate and deactivate.
@see d_sampleRateChanged()
*/
/**
Get the current sample rate that will be used during processing.
This value will remain constant between activate and deactivate.
@see d_sampleRateChanged(double)
*/
double d_getSampleRate() const noexcept;

#if DISTRHO_PLUGIN_WANT_TIMEPOS
/**
Get the current host transport time position.
This function should only be called during d_run().
You can call this during other times, but the returned position is not guaranteed to be in sync.
*/
/**
Get the current host transport time position.
This function should only be called during d_run().
You can call this during other times, but the returned position is not guaranteed to be in sync.
@note: TimePos is not supported in LADSPA and DSSI plugin formats.
*/
const TimePos& d_getTimePos() const noexcept;
#endif

#if DISTRHO_PLUGIN_WANT_LATENCY
/**
Change the plugin audio output latency to @a frames.
This function should only be called in the constructor, d_activate() and d_run().
*/
/**
Change the plugin audio output latency to @a frames.
This function should only be called in the constructor, d_activate() and d_run().
*/
void d_setLatency(const uint32_t frames) noexcept;
#endif

#if DISTRHO_PLUGIN_HAS_MIDI_OUTPUT
/**
Write a MIDI output event.
This function must only be called during d_run().
Returns false when the host buffer is full, in which case do not call this again until the next d_run().
*/
/**
Write a MIDI output event.
This function must only be called during d_run().
Returns false when the host buffer is full, in which case do not call this again until the next d_run().
*/
bool d_writeMidiEvent(const MidiEvent& midiEvent) noexcept;
#endif

protected:
/* --------------------------------------------------------------------------------------------------------
* Information */
/* --------------------------------------------------------------------------------------------------------
* Information */

/**
Get the plugin name.
Returns DISTRHO_PLUGIN_NAME by default.
*/
/**
Get the plugin name.
Returns DISTRHO_PLUGIN_NAME by default.
*/
virtual const char* d_getName() const { return DISTRHO_PLUGIN_NAME; }

/**
Get the plugin label.
A plugin label follows the same rules as Parameter::symbol, with the exception that it can start with numbers.
*/
/**
Get the plugin label.
A plugin label follows the same rules as Parameter::symbol, with the exception that it can start with numbers.
*/
virtual const char* d_getLabel() const = 0;

/**
Get the plugin author/maker.
*/
/**
Get the plugin author/maker.
*/
virtual const char* d_getMaker() const = 0;

/**
Get the plugin license name (a single line of text).
*/
/**
Get the plugin license name (a single line of text).
*/
virtual const char* d_getLicense() const = 0;

/**
Get the plugin version, in hexadecimal.
TODO format to be defined
*/
/**
Get the plugin version, in hexadecimal.
TODO format to be defined
*/
virtual uint32_t d_getVersion() const = 0;

/**
Get the plugin unique Id.
This value is used by LADSPA, DSSI and VST plugin formats.
*/
/**
Get the plugin unique Id.
This value is used by LADSPA, DSSI and VST plugin formats.
*/
virtual int64_t d_getUniqueId() const = 0;

/* --------------------------------------------------------------------------------------------------------
* Init */
/* --------------------------------------------------------------------------------------------------------
* Init */

/**
Initialize the parameter @a index.
This function will be called once, shortly after the plugin is created.
*/
/**
Initialize the parameter @a index.
This function will be called once, shortly after the plugin is created.
*/
virtual void d_initParameter(uint32_t index, Parameter& parameter) = 0;

#if DISTRHO_PLUGIN_WANT_PROGRAMS
/**
Set the name of the program @a index.
This function will be called once, shortly after the plugin is created.
Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
*/
/**
Set the name of the program @a index.
This function will be called once, shortly after the plugin is created.
Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
*/
virtual void d_initProgramName(uint32_t index, d_string& programName) = 0;
#endif

#if DISTRHO_PLUGIN_WANT_STATE
/**
Set the key name of the state @a index.
This function will be called once, shortly after the plugin is created.
Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
*/
/**
Set the key name of the state @a index.
This function will be called once, shortly after the plugin is created.
Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
*/
virtual void d_initStateKey(uint32_t index, d_string& stateKey) = 0;
#endif

/* --------------------------------------------------------------------------------------------------------
* Internal data */
/* --------------------------------------------------------------------------------------------------------
* Internal data */

/**
Get a parameter value.
The host may call this function from any context, including realtime processing.
*/
/**
Get the current value of a parameter.
The host may call this function from any context, including realtime processing.
*/
virtual float d_getParameterValue(uint32_t index) const = 0;

/**
Set a parameter value.
The host may call this function from any context, including realtime processing.
When a parameter is marked as automable, you must ensure no non-realtime operations are called.
@note This function will only be called for parameter inputs.
*/
/**
Change a parameter value.
The host may call this function from any context, including realtime processing.
When a parameter is marked as automable, you must ensure no non-realtime operations are called.
@note This function will only be called for parameter inputs.
*/
virtual void d_setParameterValue(uint32_t index, float value) = 0;

#if DISTRHO_PLUGIN_WANT_PROGRAMS
/**
Change the currently used program to @a index.
The host may call this function from any context, including realtime processing.
Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
*/
/**
Change the currently used program to @a index.
The host may call this function from any context, including realtime processing.
Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
*/
virtual void d_setProgram(uint32_t index) = 0;
#endif

#if DISTRHO_PLUGIN_WANT_STATE
/**
Change an internal state @a key to @a value.
Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
*/
/**
Change an internal state @a key to @a value.
Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
*/
virtual void d_setState(const char* key, const char* value) = 0;
#endif

/* --------------------------------------------------------------------------------------------------------
* Process */
/* --------------------------------------------------------------------------------------------------------
* Process */

/**
Activate this plugin.
*/
/**
Activate this plugin.
*/
virtual void d_activate() {}

/**
Deactivate this plugin.
*/
/**
Deactivate this plugin.
*/
virtual void d_deactivate() {}

#if DISTRHO_PLUGIN_HAS_MIDI_INPUT
/**
Run/process function for plugins with MIDI input.
@note: Some parameters might be null if there are no audio inputs/outputs or MIDI events.
*/
virtual void d_run(const float** inputs, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) = 0;
/**
Run/process function for plugins with MIDI input.
@note: Some parameters might be null if there are no audio inputs/outputs or MIDI events.
*/
virtual void d_run(const float** inputs, float** outputs, uint32_t frames,
const MidiEvent* midiEvents, uint32_t midiEventCount) = 0;
#else
/**
Run/process function for plugins without MIDI input.
@note: Some parameters might be null if there are no audio inputs or outputs.
*/
/**
Run/process function for plugins without MIDI input.
@note: Some parameters might be null if there are no audio inputs or outputs.
*/
virtual void d_run(const float** inputs, float** outputs, uint32_t frames) = 0;
#endif

/* --------------------------------------------------------------------------------------------------------
* Callbacks (optional) */
/* --------------------------------------------------------------------------------------------------------
* Callbacks (optional) */

/**
Optional callback to inform the plugin about a buffer size change.
This function will only be called when the plugin is deactivated.
@note: This value is only a hint!
Hosts might call d_run() with a higher or lower number of frames.
@see d_getBufferSize()
*/
/**
Optional callback to inform the plugin about a buffer size change.
This function will only be called when the plugin is deactivated.
@note: This value is only a hint!
Hosts might call d_run() with a higher or lower number of frames.
@see d_getBufferSize()
*/
virtual void d_bufferSizeChanged(uint32_t newBufferSize);

/**
Optional callback to inform the plugin about a sample rate change.
This function will only be called when the plugin is deactivated.
@see d_getSampleRate()
*/
/**
Optional callback to inform the plugin about a sample rate change.
This function will only be called when the plugin is deactivated.
@see d_getSampleRate()
*/
virtual void d_sampleRateChanged(double newSampleRate);

// -------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------

private:
struct PrivateData;


+ 106
- 32
distrho/DistrhoUI.hpp View File

@@ -33,75 +33,146 @@ typedef DGL::Widget UIWidget;

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------
// UI
/* ------------------------------------------------------------------------------------------------------------
* DPF UI */

/**
DPF UI class from where UI instances are created.

TODO.

you should not have to call setSize during construction,
that is handled by d_initSize
if you want to change size later on you should use setSize and then d_setSize to report to host
*/
class UI : public UIWidget
{
public:
/**
UI class constructor.
*/
UI();

/**
Destructor.
*/
virtual ~UI();

// -------------------------------------------------------------------
// Host DSP State
/* --------------------------------------------------------------------------------------------------------
* Host DSP state */

/**
Get the current sample rate used in plugin processing.
@see d_sampleRateChanged(double)
*/
double d_getSampleRate() const noexcept;
void d_editParameter(const uint32_t index, const bool started);
void d_setParameterValue(const uint32_t index, const float value);

/**
TODO: Document this.
*/
void d_editParameter(const uint32_t index, const bool started);

/**
TODO: Document this.
*/
void d_setParameterValue(const uint32_t index, const float value);

#if DISTRHO_PLUGIN_WANT_STATE
void d_setState(const char* const key, const char* const value);
/**
TODO: Document this.
*/
void d_setState(const char* const key, const char* const value);
#endif

#if DISTRHO_PLUGIN_IS_SYNTH
void d_sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity);
/**
TODO: Document this.
*/
void d_sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity);
#endif

// -------------------------------------------------------------------
// Host UI State
/* --------------------------------------------------------------------------------------------------------
* Host UI state */

/**
TODO: Document this.
never call this from the constructor
*/
void d_setSize(const uint width, const uint height);

#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
// -------------------------------------------------------------------
// Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!!
/* --------------------------------------------------------------------------------------------------------
* Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */

/**
TODO: Document this.
*/
void* d_getPluginInstancePointer() const noexcept;
#endif

protected:
// -------------------------------------------------------------------
// Basic Information

virtual const char* d_getName() const noexcept { return DISTRHO_PLUGIN_NAME; }
virtual uint d_getWidth() const noexcept = 0;
virtual uint d_getHeight() const noexcept = 0;

// -------------------------------------------------------------------
// DSP Callbacks

/* --------------------------------------------------------------------------------------------------------
* Init */

/**
Set the initial UI size.
This function will be called once, shortly after the UI is created.
@see d_setSize(uint,uint)
*/
virtual void d_initSize(uint& width, uint& height) = 0;

/* --------------------------------------------------------------------------------------------------------
* DSP/Plugin Callbacks */

/**
A parameter has changed on the plugin side.
This is called by the host to inform the UI about parameter changes.
*/
virtual void d_parameterChanged(uint32_t index, float value) = 0;

#if DISTRHO_PLUGIN_WANT_PROGRAMS
/**
The current program has changed on the plugin side.
This is called by the host to inform the UI about program changes.
*/
virtual void d_programChanged(uint32_t index) = 0;
#endif

#if DISTRHO_PLUGIN_WANT_STATE
/**
A state has changed on the plugin side.
This is called by the host to inform the UI about state changes.
*/
virtual void d_stateChanged(const char* key, const char* value) = 0;
#endif

// -------------------------------------------------------------------
// DSP Callbacks (optional)
/* --------------------------------------------------------------------------------------------------------
* DSP/Plugin Callbacks (optional) */

/**
Optional callback to inform the UI about a sample rate change on the plugin side.
@see d_getSampleRate()
*/
virtual void d_sampleRateChanged(double newSampleRate);

// -------------------------------------------------------------------
// UI Callbacks (optional)
/* --------------------------------------------------------------------------------------------------------
* UI Callbacks (optional) */

/**
TODO: Document this.
*/
virtual void d_uiIdle() {}

#if ! DISTRHO_UI_USE_NTK
// updates window openGL state
virtual void d_uiReshape(int width, int height);
/**
OpenGL reshape function, called when the host window is resized.
You can reimplement this function for a custom OpenGL state.
@see Window::onReshape(uint,uint)
*/
virtual void d_uiReshape(uint width, uint height);
#endif

// -------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------

private:
struct PrivateData;
@@ -120,12 +191,15 @@ private:
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI)
};

// -----------------------------------------------------------------------
// Create UI, entry point
/* ------------------------------------------------------------------------------------------------------------
* Create UI, entry point */

/**
TODO.
*/
extern UI* createUI();

// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------

END_NAMESPACE_DISTRHO



+ 1
- 1
distrho/src/DistrhoPluginJack.cpp View File

@@ -107,7 +107,7 @@ public:
if (const char* const name = jack_get_client_name(fClient))
fUI.setTitle(name);
else
fUI.setTitle(DISTRHO_PLUGIN_NAME);
fUI.setTitle(fPlugin.getName());

fUI.exec(this);
}


+ 1
- 1
distrho/src/DistrhoUI.cpp View File

@@ -99,7 +99,7 @@ void UI::d_sampleRateChanged(double) {}
// UI Callbacks (optional)

#if ! DISTRHO_UI_USE_NTK
void UI::d_uiReshape(int width, int height)
void UI::d_uiReshape(uint width, uint height)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


+ 14
- 16
distrho/src/DistrhoUIInternal.hpp View File

@@ -62,6 +62,10 @@ struct UI::PrivateData {
void* dspPtr;
#endif

// UI
uint initialWidth;
uint initialHeight;

// Callbacks
editParamFunc editParamCallbackFunc;
setParamFunc setParamCallbackFunc;
@@ -76,6 +80,8 @@ struct UI::PrivateData {
#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
dspPtr(d_lastUiDspPtr),
#endif
initialWidth(0),
initialHeight(0),
editParamCallbackFunc(nullptr),
setParamCallbackFunc(nullptr),
setStateCallbackFunc(nullptr),
@@ -128,6 +134,9 @@ struct UI::PrivateData {

void setSizeCallback(const uint width, const uint height)
{
DISTRHO_SAFE_ASSERT_RETURN(initialWidth != 0,);
DISTRHO_SAFE_ASSERT_RETURN(initialHeight != 0,);

if (setSizeCallbackFunc != nullptr)
setSizeCallbackFunc(ptr, width, height);
}
@@ -157,8 +166,8 @@ public:
{
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,);

const int width = fUI->d_getWidth();
const int height = fUI->d_getHeight();
uint width = 0, height = 0;
fUI->d_initSize(width, height);

// set widget size
fUI->setSize(width, height);
@@ -191,7 +200,7 @@ protected:
fIsReady = true;
}
#else
void onReshape(int width, int height) override
void onReshape(uint width, uint height) override
{
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,);

@@ -237,25 +246,14 @@ public:

// -------------------------------------------------------------------

const char* getName() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr, "");

return fUI->d_getName();
}

uint getWidth() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr, 0);

return fUI->d_getWidth();
return glWindow.getWidth();
}

uint getHeight() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr, 0);

return fUI->d_getHeight();
return glWindow.getHeight();
}

// -------------------------------------------------------------------


+ 1
- 1
distrho/src/DistrhoUILV2.cpp View File

@@ -91,7 +91,7 @@ public:
}

if (! hasTitle)
fUI.setTitle(fUI.getName());
fUI.setTitle(DISTRHO_PLUGIN_NAME);
}

// -------------------------------------------------------------------


Loading…
Cancel
Save