Skip to content

Commit

Permalink
Make plugins resizable, start SlicerT UI update
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielKauss committed Aug 14, 2024
1 parent bda1a9c commit 4d26b30
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 67 deletions.
7 changes: 7 additions & 0 deletions include/InstrumentTrackWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "ModelView.h"
#include "SerializingObject.h"
#include "PluginView.h"

class QLabel;
class QLineEdit;
Expand Down Expand Up @@ -67,6 +68,11 @@ class InstrumentTrackWindow : public QWidget, public ModelView,
InstrumentTrackWindow( InstrumentTrackView * _tv );
~InstrumentTrackWindow() override;

// Is this needed?
/* void resizeEvent(QResizeEvent* event) override { m_instrumentView->resize(size()); } */
void resizeEvent(QResizeEvent* event) override;


// parent for all internal tab-widgets
TabWidget * tabWidgetParent()
{
Expand Down Expand Up @@ -152,6 +158,7 @@ protected slots:
InstrumentSoundShapingView * m_ssView;
InstrumentFunctionNoteStackingView* m_noteStackingView;
InstrumentFunctionArpeggioView* m_arpeggioView;
QWidget* m_instrumentFunctionsView; // container of note stacking and arpeggio
InstrumentMidiIOView * m_midiView;
EffectRackView * m_effectView;
InstrumentTuningView *m_tuningView;
Expand Down
1 change: 1 addition & 0 deletions include/PluginView.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class LMMS_EXPORT PluginView : public QWidget, public ModelView
ModelView( _plugin, this )
{
}
bool m_isResizable = false;

} ;

Expand Down
2 changes: 1 addition & 1 deletion plugins/LadspaEffect/cmt/cmt
Submodule cmt updated 3 files
+4 −1 src/cmt.h
+1 −1 src/delay.cpp
+4 −0 src/init.cpp
2 changes: 1 addition & 1 deletion plugins/LadspaEffect/swh/ladspa
Submodule ladspa updated 1 files
+1 −2 revdelay_1605.xml
1 change: 1 addition & 0 deletions plugins/SlicerT/SlicerT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ void SlicerT::playNote(NotePlayHandle* handle, SampleFrame* workingBuffer)
void SlicerT::deleteNotePluginData(NotePlayHandle* handle)
{
delete static_cast<PlaybackState*>(handle->m_pluginData);
emit isPlaying(-1, 0, 0);
}

// uses the spectral flux to determine the change in magnitude
Expand Down
67 changes: 52 additions & 15 deletions plugins/SlicerT/SlicerTView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@

#include <QDropEvent>
#include <QFileInfo>
#include <qlayout.h>
#include <qsizepolicy.h>
#include <qwidget.h>

#include "Clipboard.h"
#include "DataFile.h"
#include "Engine.h"
#include "InstrumentTrack.h"
#include "InstrumentView.h"
#include "PixmapButton.h"
#include "SampleLoader.h"
#include "SlicerT.h"
#include "Song.h"
#include "StringPairDrag.h"
#include "Track.h"
#include "embed.h"
Expand All @@ -43,13 +46,17 @@ namespace lmms {
namespace gui {

SlicerTView::SlicerTView(SlicerT* instrument, QWidget* parent)
: InstrumentViewFixedSize(instrument, parent)
: InstrumentView(instrument, parent)
, m_slicerTParent(instrument)
{
// window settings
setAcceptDrops(true);
setAutoFillBackground(true);

setMaximumSize(QSize(500, 500));
setMinimumSize(QSize(250, 250));
m_isResizable = true;

// render background
QPalette pal;
pal.setBrush(backgroundRole(), PLUGIN_NAME::getIconPixmap("artwork"));
Expand All @@ -64,36 +71,32 @@ SlicerTView::SlicerTView(SlicerT* instrument, QWidget* parent)
m_snapSetting->setModel(&m_slicerTParent->m_sliceSnap);

m_syncToggle = new LedCheckBox("Sync", this, tr("SyncToggle"), LedCheckBox::LedColor::Green);
m_syncToggle->move(135, 187);
m_syncToggle->setToolTip(tr("Enable BPM sync"));
m_syncToggle->setModel(&m_slicerTParent->m_enableSync);

m_bpmBox = new LcdSpinBox(3, "19purple", this);
m_bpmBox->move(130, 201);
m_bpmBox->setToolTip(tr("Original sample BPM"));
m_bpmBox->setModel(&m_slicerTParent->m_originalBPM);

m_noteThresholdKnob = createStyledKnob();
m_noteThresholdKnob->move(10, 197);
m_noteThresholdKnob->setToolTip(tr("Threshold used for slicing"));
m_noteThresholdKnob->setModel(&m_slicerTParent->m_noteThreshold);

m_fadeOutKnob = createStyledKnob();
m_fadeOutKnob->move(64, 197);
m_fadeOutKnob->setToolTip(tr("Fade Out per note in milliseconds"));
m_fadeOutKnob->setModel(&m_slicerTParent->m_fadeOutFrames);

m_midiExportButton = new QPushButton(this);
m_midiExportButton->move(199, 150);
m_midiExportButton->setIcon(PLUGIN_NAME::getIconPixmap("copy_midi"));
m_midiExportButton->setToolTip(tr("Copy midi pattern to clipboard"));
connect(m_midiExportButton, &PixmapButton::clicked, this, &SlicerTView::exportMidi);

m_resetButton = new QPushButton(this);
m_resetButton->move(18, 150);
m_resetButton->setIcon(PLUGIN_NAME::getIconPixmap("reset_slices"));
m_resetButton->setToolTip(tr("Reset Slices"));
connect(m_resetButton, &PixmapButton::clicked, m_slicerTParent, &SlicerT::updateSlices);

update();
}

Knob* SlicerTView::createStyledKnob()
Expand Down Expand Up @@ -181,13 +184,47 @@ void SlicerTView::paintEvent(QPaintEvent* pe)
brush.setPen(QColor(255, 255, 255));
brush.setFont(QFont(brush.font().family(), 7, -1, false));

brush.drawText(8, s_topTextY, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Reset"));
brush.drawText(188, s_topTextY, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Midi"));
int y1_text = m_y1 + 22;
int y2_text = m_y2 + 22;

brush.drawText(m_x1 - 12, y1_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Reset"));
brush.drawText(m_x4 - 12, y1_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Midi"));

brush.drawText(m_x1 - 25, y2_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Threshold"));
brush.drawText(m_x2 - 25, y2_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Fade Out"));
brush.drawText(m_x3 - 16, y2_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("BPM"));
brush.drawText(m_x4 - 8, y2_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Snap"));
}

void SlicerTView::resizeEvent(QResizeEvent * re)
{
QPalette pal = palette();
pal.setBrush(backgroundRole(), PLUGIN_NAME::getIconPixmap("artwork").scaled(size(), Qt::IgnoreAspectRatio));
setPalette(pal);

m_y1 = height() - 100;
m_y2 = height() - 50;

m_x1 = width() * 0.2f;
m_x2 = width() * 0.4f;
m_x3 = width() * 0.6f;
m_x4 = width() * 0.8f;

// first row
m_resetButton->move(m_x1 - 12, m_y1);
m_midiExportButton->move(m_x4 - 12, m_y1);

// second row
m_noteThresholdKnob->move(m_x1 - 25, m_y2);
m_fadeOutKnob->move(m_x2 - 25, m_y2);

m_bpmBox->move(m_x3 - 16, m_y2);
m_syncToggle->move(m_x3 - 7, m_y2 - 16);

m_snapSetting->move(m_x4 - 8, m_y2);

brush.drawText(8, s_bottomTextY, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Threshold"));
brush.drawText(63, s_bottomTextY, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Fade Out"));
brush.drawText(127, s_bottomTextY, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("BPM"));
brush.drawText(188, s_bottomTextY, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Snap"));
m_wf->resize(width() - 2, height() - 125);
m_wf->updateSize(width() - 2, height() - 125);
}

} // namespace gui
Expand Down
21 changes: 15 additions & 6 deletions plugins/SlicerT/SlicerTView.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@
#include <QPushButton>

#include "ComboBox.h"
#include "Instrument.h"
#include "InstrumentView.h"
#include "Knob.h"
#include "LcdSpinBox.h"
#include "LedCheckBox.h"
#include "PixmapButton.h"
#include "SlicerTWaveform.h"

namespace lmms {
Expand All @@ -42,7 +40,7 @@ class SlicerT;

namespace gui {

class SlicerTView : public InstrumentViewFixedSize
class SlicerTView : public InstrumentView
{
Q_OBJECT

Expand All @@ -59,10 +57,13 @@ public slots:
static constexpr int s_bottomTextY = 220;

protected:
virtual void dragEnterEvent(QDragEnterEvent* dee);
virtual void dropEvent(QDropEvent* de);
virtual void dragEnterEvent(QDragEnterEvent* dee) override;
virtual void dropEvent(QDropEvent* de) override;

virtual void paintEvent(QPaintEvent* pe);
virtual void paintEvent(QPaintEvent* pe) override;
/* QSize sizeHint() const override { return QSize(150, 150); } */
/* QSize minimumSizeHint() const override { return QSize(300, 300); } */
void resizeEvent(QResizeEvent* event) override;

private:
SlicerT* m_slicerTParent;
Expand All @@ -79,6 +80,14 @@ public slots:
SlicerTWaveform* m_wf;

Knob* createStyledKnob();

int m_x1;
int m_x2;
int m_x3;
int m_x4;

int m_y1;
int m_y2;
};
} // namespace gui
} // namespace lmms
Expand Down
54 changes: 36 additions & 18 deletions plugins/SlicerT/SlicerTWaveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace gui {

static QColor s_emptyColor = QColor(0, 0, 0, 0);
static QColor s_waveformColor = QColor(123, 49, 212);
static QColor s_waveformBgColor = QColor(255, 255, 255, 0);
static QColor s_waveformBgColor = QColor(0, 0, 0, 255);
static QColor s_waveformMaskColor = QColor(151, 65, 255); // update this if s_waveformColor changes
static QColor s_waveformInnerColor = QColor(183, 124, 255);

Expand All @@ -56,18 +56,19 @@ SlicerTWaveform::SlicerTWaveform(int totalWidth, int totalHeight, SlicerT* instr
: QWidget(parent)
, m_width(totalWidth)
, m_height(totalHeight)
, m_seekerHeight(totalHeight * 0.33f)
, m_seekerWidth(totalWidth - s_seekerHorMargin * 2)
, m_editorHeight(totalHeight - s_seekerHeight - s_middleMargin)
, m_editorHeight(totalHeight - m_seekerHeight - s_middleMargin)
, m_editorWidth(totalWidth)
, m_sliceArrow(PLUGIN_NAME::getIconPixmap("slice_indicator_arrow"))
, m_seeker(QPixmap(m_seekerWidth, s_seekerHeight))
, m_seekerWaveform(QPixmap(m_seekerWidth, s_seekerHeight))
, m_seeker(QPixmap(m_seekerWidth, m_seekerHeight))
, m_seekerWaveform(QPixmap(m_seekerWidth, m_seekerHeight))
, m_editorWaveform(QPixmap(m_editorWidth, m_editorHeight))
, m_sliceEditor(QPixmap(totalWidth, m_editorHeight))
, m_emptySampleIcon(embed::getIconPixmap("sample_track"))
, m_slicerTParent(instrument)
{
setFixedSize(m_width, m_height);
resize(m_width, m_height);
setMouseTracking(true);

m_seekerWaveform.fill(s_waveformBgColor);
Expand All @@ -82,6 +83,21 @@ SlicerTWaveform::SlicerTWaveform(int totalWidth, int totalHeight, SlicerT* instr
updateUI();
}

void SlicerTWaveform::updateSize(int newWidth, int newHeight)
{
m_width = newWidth;
m_height = newHeight;
m_seekerWidth = m_width - s_seekerHorMargin * 2;
m_seekerHeight = m_height * 0.33f;
m_editorWidth = m_width;
m_editorHeight = m_height - m_seekerHeight - s_middleMargin;

m_seeker = QPixmap(m_seekerWidth, m_seekerHeight);
m_seekerWaveform = QPixmap(m_seekerWidth, m_seekerHeight);
m_editorWaveform = QPixmap(m_editorWidth, m_editorHeight);
m_sliceEditor = QPixmap(m_width, m_editorHeight);
updateUI();
}
void SlicerTWaveform::drawSeekerWaveform()
{
m_seekerWaveform.fill(s_waveformBgColor);
Expand All @@ -90,7 +106,8 @@ void SlicerTWaveform::drawSeekerWaveform()
brush.setPen(s_waveformColor);

const auto& sample = m_slicerTParent->m_originalSample;
const auto waveform = SampleWaveform::Parameters{sample.data(), sample.sampleSize(), sample.amplification(), sample.reversed()};
const auto waveform
= SampleWaveform::Parameters{sample.data(), sample.sampleSize(), sample.amplification(), sample.reversed()};
const auto rect = QRect(0, 0, m_seekerWaveform.width(), m_seekerWaveform.height());
SampleWaveform::visualize(waveform, brush, rect);

Expand All @@ -102,15 +119,16 @@ void SlicerTWaveform::drawSeekerWaveform()

void SlicerTWaveform::drawSeeker()
{
m_seeker.fill(s_emptyColor);
m_seeker.fill(s_waveformBgColor);
if (m_slicerTParent->m_originalSample.sampleSize() <= 1) { return; }
QPainter brush(&m_seeker);
brush.drawPixmap(0, 0, m_seekerWaveform);

brush.setPen(s_sliceColor);
for (float sliceValue : m_slicerTParent->m_slicePoints)
{
float xPos = sliceValue * m_seekerWidth;
brush.drawLine(xPos, 0, xPos, s_seekerHeight);
brush.drawLine(xPos, 0, xPos, m_seekerHeight);
}

float seekerStartPosX = m_seekerStart * m_seekerWidth;
Expand All @@ -122,16 +140,16 @@ void SlicerTWaveform::drawSeeker()
float noteEndPosX = (m_noteEnd - m_noteStart) * m_seekerWidth;

brush.setPen(s_playColor);
brush.drawLine(noteCurrentPosX, 0, noteCurrentPosX, s_seekerHeight);
brush.fillRect(noteStartPosX, 0, noteEndPosX, s_seekerHeight, s_playHighlightColor);
brush.drawLine(noteCurrentPosX, 0, noteCurrentPosX, m_seekerHeight);
brush.fillRect(noteStartPosX, 0, noteEndPosX, m_seekerHeight, s_playHighlightColor);

brush.fillRect(seekerStartPosX, 0, seekerMiddleWidth - 1, s_seekerHeight, s_seekerHighlightColor);
brush.fillRect(seekerStartPosX, 0, seekerMiddleWidth - 1, m_seekerHeight, s_seekerHighlightColor);

brush.fillRect(0, 0, seekerStartPosX, s_seekerHeight, s_seekerShadowColor);
brush.fillRect(seekerEndPosX - 1, 0, m_seekerWidth, s_seekerHeight, s_seekerShadowColor);
brush.fillRect(0, 0, seekerStartPosX, m_seekerHeight, s_seekerShadowColor);
brush.fillRect(seekerEndPosX - 1, 0, m_seekerWidth, m_seekerHeight, s_seekerShadowColor);

brush.setPen(QPen(s_seekerColor, 1));
brush.drawRect(seekerStartPosX, 0, seekerMiddleWidth - 1, s_seekerHeight - 1); // -1 needed
brush.drawRect(seekerStartPosX, 0, seekerMiddleWidth - 1, m_seekerHeight - 1); // -1 needed
}

void SlicerTWaveform::drawEditorWaveform()
Expand All @@ -147,7 +165,8 @@ void SlicerTWaveform::drawEditorWaveform()
float zoomOffset = (m_editorHeight - m_zoomLevel * m_editorHeight) / 2;

const auto& sample = m_slicerTParent->m_originalSample;
const auto waveform = SampleWaveform::Parameters{sample.data() + startFrame, endFrame - startFrame, sample.amplification(), sample.reversed()};
const auto waveform = SampleWaveform::Parameters{
sample.data() + startFrame, endFrame - startFrame, sample.amplification(), sample.reversed()};
const auto rect = QRect(0, zoomOffset, m_editorWidth, m_zoomLevel * m_editorHeight);
SampleWaveform::visualize(waveform, brush, rect);

Expand Down Expand Up @@ -248,7 +267,7 @@ void SlicerTWaveform::updateClosest(QMouseEvent* me)
m_closestObject = UIObjects::Nothing;
m_closestSlice = -1;

if (me->y() < s_seekerHeight)
if (me->y() < m_seekerHeight)
{
if (std::abs(normalizedClickSeeker - m_seekerStart) < s_distanceForClick)
{
Expand Down Expand Up @@ -416,9 +435,8 @@ void SlicerTWaveform::wheelEvent(QWheelEvent* we)
void SlicerTWaveform::paintEvent(QPaintEvent* pe)
{
QPainter p(this);
p.drawPixmap(s_seekerHorMargin, 0, m_seekerWaveform);
p.drawPixmap(s_seekerHorMargin, 0, m_seeker);
p.drawPixmap(0, s_seekerHeight + s_middleMargin, m_sliceEditor);
p.drawPixmap(0, m_seekerHeight + s_middleMargin, m_sliceEditor);
}
} // namespace gui
} // namespace lmms
Loading

0 comments on commit 4d26b30

Please sign in to comment.