Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample editor love (on dev branch) #1302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
be1610d
[SampleEditor] correct volume envelope reading and crash when editiin…
charbeljc Jun 11, 2021
442f146
envelope editing: remove duplicate code
charbeljc Jun 11, 2021
89602fd
wave editors: always track mouse movements
charbeljc Jun 14, 2021
ecd7154
remove code duplication for envelope painting
charbeljc Jun 14, 2021
2bb9383
don't move !
charbeljc Jun 14, 2021
086768a
using references instead of pointers is nicer
charbeljc Jun 14, 2021
453537b
add EnvelopeEditMode enum, more refs instead of pointers
charbeljc Jun 14, 2021
9546303
highlight selected/selectable envelope point on mouse moves
charbeljc Jun 14, 2021
bad9452
highlight selected frame slider in MainSampleWaveDisplay
charbeljc Jun 14, 2021
f765730
use manhattanLength() to choose frame slider
charbeljc Jun 14, 2021
a33e62a
envelope editing: dont stop dragging when mouse leave widgets
charbeljc Jun 14, 2021
9c872f1
allow empty envelopes
charbeljc Jun 15, 2021
2b7fe5a
make the main wave widget more intuitive
charbeljc Jun 15, 2021
f3e6bc3
show envelope value only when dragging
charbeljc Jun 15, 2021
965be0c
update layer's wave preview on change
charbeljc Jun 15, 2021
400b42a
hit enter everywhere in editor to play sample
charbeljc Jun 15, 2021
69cbef3
use manhattan distance for envelope point selection
charbeljc Jun 15, 2021
b11d4f5
avoid crash when no point is selected for removal
charbeljc Jun 17, 2021
5bd9059
make SampleEditor::m_bSampleEditorClean private & initialize it in ctor
charbeljc Jun 17, 2021
de93d70
add public method InstrumentEditorPanel::updateWaveDisplay()
charbeljc Jun 17, 2021
ad7527c
initialize MainSampleWaveDisplay::m_SelectedSlider in ctor
charbeljc Jun 17, 2021
fae5772
show envelope point value on hover
charbeljc Jun 17, 2021
2c06958
highlight first and last point also when selected
charbeljc Jun 17, 2021
8478ce1
factorize some code in MainSampleWaveDisplay
charbeljc Jun 17, 2021
b00c394
merge envelope points at same frame
charbeljc Jun 17, 2021
6c9256e
naming conventions
charbeljc Jun 17, 2021
d09d796
update ChangeLog
charbeljc Jun 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"Custom".
- Via a colored button the particular line color can now be
adjusted using a QColorDialog
* InstrumentEditor UX improvements:
- rework start/end/loop frame slider selection and motion.
- rework velocity/pan envelope editing

20xx-xx-xx the hydrogen team <[email protected]>
* Release 1.1
Expand Down
5 changes: 4 additions & 1 deletion src/gui/src/InstrumentEditor/InstrumentEditorPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ void InstrumentEditorPanel::selectLayer( int nLayer )
m_nLayer = nLayer;
}


void InstrumentEditorPanel::updateWaveDisplay()
{
selectLayer ( m_nLayer ); // trigger a redisplay of wave preview
}


2 changes: 2 additions & 0 deletions src/gui/src/InstrumentEditor/InstrumentEditorPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class InstrumentEditorPanel : public QWidget, private H2Core::Object, public Eve
return m_nLayer;
}

void updateWaveDisplay();

public slots:
void notifyOfDrumkitChange();

Expand Down
118 changes: 76 additions & 42 deletions src/gui/src/SampleEditor/MainSampleWaveDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ MainSampleWaveDisplay::MainSampleWaveDisplay(QWidget* pParent)
m_nStartFramePosition = 25;
m_nLoopFramePosition = 25;
m_nEndFramePosition = width() -25;
m_bMove = false;
m_nLocator = -1;
m_bUpdatePosition = false;
m_nSampleLength = 0;

m_bStartSliderIsMoved = false;
m_bLoopSliderIsMoved = false;
m_bEndSliderIsmoved = false;

m_SelectedSlider = NONE;
setMouseTracking(true);
}


Expand All @@ -87,6 +89,19 @@ void MainSampleWaveDisplay::paintLocatorEvent( int pos, bool updateposi)
update();
}

static void set_paint_color(QPainter & painter, const QColor & color, bool selected, MainSampleWaveDisplay::Slider which)
{
if (!selected) {
painter.setPen( color );
} else {
QColor highlight = QColor(std::min(255, color.red() + 20 + 20 * (which == MainSampleWaveDisplay::END)),
std::min(255, color.green() + 20 + 20 * (which == MainSampleWaveDisplay::START)),
std::min(255, color.blue() + 20 + 20 * (which == MainSampleWaveDisplay::LOOP)));

painter.setPen ( highlight );
}
}

void MainSampleWaveDisplay::paintEvent(QPaintEvent *ev)
{
QPainter painter( this );
Expand Down Expand Up @@ -125,18 +140,22 @@ void MainSampleWaveDisplay::paintEvent(QPaintEvent *ev)
painter.drawLine( 0, VCenterr, width(),VCenterr );

QFont font;

QColor startColor = QColor( 32, 173, 0, 200 );
QColor endColor = QColor( 217, 68, 0, 200 );
QColor loopColor = QColor( 93, 170, 254, 200 );
font.setWeight( 63 );
painter.setFont( font );
//start frame pointer
painter.setPen( QColor( 32, 173, 0, 200 ) );
set_paint_color(painter, startColor, m_SelectedSlider == START, m_SelectedSlider);
painter.drawLine( m_nStartFramePosition, 4, m_nStartFramePosition, height() -4 );
painter.drawText( m_nStartFramePosition -10, 250, 10,20, Qt::AlignRight, "S" );
//endframe pointer
painter.setPen( QColor( 217, 68, 0, 200 ) );
set_paint_color(painter, endColor, m_SelectedSlider == END, m_SelectedSlider);
painter.drawLine( m_nEndFramePosition, 4, m_nEndFramePosition, height() -4 );
painter.drawText( m_nEndFramePosition -10, 123, 10, 20, Qt::AlignRight, "E" );
//loopframe pointer
painter.setPen( QColor( 93, 170, 254, 200 ) );
set_paint_color(painter, loopColor, m_SelectedSlider == LOOP, m_SelectedSlider);
painter.drawLine( m_nLoopFramePosition, 4, m_nLoopFramePosition, height() -4 );
painter.drawText( m_nLoopFramePosition , 0, 10, 20, Qt::AlignLeft, "L" );

Expand Down Expand Up @@ -199,26 +218,41 @@ void MainSampleWaveDisplay::updateDisplay( const QString& filename )
update();

}
void MainSampleWaveDisplay::mouseUpdateDone() {
HydrogenApp::get_instance()->getSampleEditor()->returnAllMainWaveDisplayValues();
m_bStartSliderIsMoved = false;
m_bLoopSliderIsMoved = false;
m_bEndSliderIsmoved = false;
}


void MainSampleWaveDisplay::mouseMoveEvent(QMouseEvent *ev)
{
testPosition( ev );
if (ev->buttons() && Qt::LeftButton) {
testPosition( ev );
} else {
chooseSlider( ev );
}
update();
mouseUpdateDone();
}

void MainSampleWaveDisplay::mousePressEvent(QMouseEvent *ev)
{
chooseSlider( ev );
testPosition( ev );
update();
mouseUpdateDone();
}

void MainSampleWaveDisplay::testPosition( QMouseEvent *ev )
{
assert(ev);

//startframepointer
if (ev->y()>=200 ) {
m_nStartFramePosition = ev->x() ;
int x = std::min(width() - 25, std::max(25, ev->x()));

if ( m_SelectedSlider == START ) {
m_nStartFramePosition = x;
m_bStartSliderIsMoved = true;
if ( m_nStartFramePosition > m_nLoopFramePosition ){
m_nLoopFramePosition = m_nStartFramePosition;
Expand All @@ -228,58 +262,58 @@ void MainSampleWaveDisplay::testPosition( QMouseEvent *ev )
m_nEndFramePosition = m_nStartFramePosition;
m_bEndSliderIsmoved = true;
}
// update();
}

//loopframeposition
else if (ev->y()<=65 ) {
m_nLoopFramePosition = ev->x() ;
m_bLoopSliderIsMoved = true;
if ( m_nLoopFramePosition < m_nStartFramePosition ){
m_nStartFramePosition = m_nLoopFramePosition;
m_bStartSliderIsMoved = true;
}
if ( m_nLoopFramePosition > m_nEndFramePosition ){
m_nEndFramePosition = m_nLoopFramePosition;
m_bEndSliderIsmoved = true;
else if ( m_SelectedSlider == LOOP ) {
if (x >= m_nStartFramePosition && x <= m_nEndFramePosition ) {
m_nLoopFramePosition = x ;
m_bLoopSliderIsMoved = true;
}
// update();
}
//endframeposition
else if ( ev->y() >= 86 && ev->y() <= 179 ) {
m_nEndFramePosition = ev->x() ;
m_bEndSliderIsmoved = true;
else if ( m_SelectedSlider == END) {
if (x >= m_nStartFramePosition) {
m_nEndFramePosition = x ;
m_bEndSliderIsmoved = true;
}
if ( m_nEndFramePosition < m_nLoopFramePosition ){
m_nLoopFramePosition = m_nEndFramePosition;
m_bLoopSliderIsMoved = true;
}
if ( m_nEndFramePosition < m_nStartFramePosition ){
m_nStartFramePosition = m_nEndFramePosition;
m_bStartSliderIsMoved = true;
}
// update();
}

if ( ( m_nStartFramePosition ) >= width() -25 ) m_nStartFramePosition =width() -25;
if ( ( m_nLoopFramePosition ) >= width() -25 ) m_nLoopFramePosition =width() -25;
if ( ( m_nEndFramePosition ) >= width() -25 ) m_nEndFramePosition =width() -25;
if ( ( m_nStartFramePosition ) <= 25 ) m_nStartFramePosition = 25;
if ( ( m_nLoopFramePosition ) <= 25 ) m_nLoopFramePosition = 25;
if ( ( m_nEndFramePosition ) <= 25 ) m_nEndFramePosition = 25;
}


void MainSampleWaveDisplay::mouseReleaseEvent(QMouseEvent *ev)
{
m_SelectedSlider = NONE;
update();
bool test = HydrogenApp::get_instance()->getSampleEditor()->returnAllMainWaveDisplayValues();

if (test){
m_bStartSliderIsMoved = false;
m_bLoopSliderIsMoved = false;
m_bEndSliderIsmoved = false;
}
mouseUpdateDone();
}




void MainSampleWaveDisplay::chooseSlider(QMouseEvent * ev)
{
assert(ev);

QPoint start = QPoint(m_nStartFramePosition, height());
QPoint end = QPoint(m_nEndFramePosition, height() / 2);
QPoint loop = QPoint(m_nLoopFramePosition, 0);

int ds = (ev->pos() - start).manhattanLength();
int de = (ev->pos() - end).manhattanLength();
int dl = (ev->pos() - loop).manhattanLength();
m_SelectedSlider = NONE;

if (ds <= de && ds <= dl) {
m_SelectedSlider = START;
} else if (de < ds && de <= dl) {
m_SelectedSlider = END;
} else if (dl < ds && dl < de) {
m_SelectedSlider = LOOP;
}
}

14 changes: 13 additions & 1 deletion src/gui/src/SampleEditor/MainSampleWaveDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class MainSampleWaveDisplay : public QWidget, public H2Core::Object
Q_OBJECT

public:

enum Slider {
NONE,
START,
LOOP,
END
};

explicit MainSampleWaveDisplay(QWidget* pParent);
~MainSampleWaveDisplay();

Expand All @@ -50,17 +58,21 @@ class MainSampleWaveDisplay : public QWidget, public H2Core::Object
int m_nStartFramePosition;
int m_nLoopFramePosition;
int m_nEndFramePosition;
bool m_bMove;

bool m_bStartSliderIsMoved;
bool m_bLoopSliderIsMoved;
bool m_bEndSliderIsmoved;

Slider m_SelectedSlider;


private:
virtual void mouseMoveEvent(QMouseEvent *ev);
virtual void mousePressEvent(QMouseEvent *ev);
virtual void mouseReleaseEvent(QMouseEvent *ev);
void testPosition( QMouseEvent *ev );
void chooseSlider( QMouseEvent *ev );
void mouseUpdateDone();

QPixmap m_background;
int* m_pPeakDatal;
Expand Down
Loading