Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 45 additions & 1 deletion include/PatternEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,24 @@

#include "Editor.h"
#include "TrackContainerView.h"
#include "AutomatableModel.h"

class QLabel;
class QScrollBar;

namespace lmms
{

class IntModel;
class PatternStore;

namespace gui
{

class AutomatableSlider;
class ComboBox;
class TimeLineWidget;


class PatternEditor : public TrackContainerView
{
Q_OBJECT
Expand All @@ -65,18 +70,44 @@ public slots:
void cloneClip();
void updateMaxSteps();

signals:
void zoomLevelChanged();
void offsetValueChanged();
void zoomControlsVisibilityChanged(bool show);

protected:
double getZoom() const
{
// The zoom level is calculated such as exactly one bar is visible when the zoom slider is at its maximum value,
// and the whole pattern is visible when the zoom slider is at its minimum value.
return 1 + m_zoomingModel->value() * (m_maxClipLength / TimePos::ticksPerBar() - 1)
/ static_cast<double>(m_zoomingModel->maxValue());
}

protected slots:
void dropEvent(QDropEvent * de ) override;
void resizeEvent(QResizeEvent* de) override;
void updatePosition();
void updatePixelsPerBar();
void updateScrollBar();

private:
void wheelEvent(QWheelEvent* we) override;

IntModel* m_zoomingModel;
QScrollBar* m_leftRightScroll;

PatternStore* m_ps;
TimeLineWidget* m_timeLine;
int m_trackHeadWidth;
tick_t m_maxClipLength;
void makeSteps( bool clone );

private slots:
void zoomingChanged();
void horizontalScrollChanged();

friend class PatternEditorWindow;
};


Expand All @@ -89,14 +120,27 @@ Q_OBJECT

QSize sizeHint() const override;

double zoomLevel() const
{
return m_editor->getZoom();
}

double horizontalScrollValue() const;

PatternEditor* m_editor;

public slots:
void play() override;
void stop() override;

void showZoomControls(bool show);

private:
AutomatableSlider* m_zoomingSlider;
ComboBox* m_patternComboBox;

QAction* m_zoomIconAction;
QAction* m_zoomSliderAction;
};


Expand Down
20 changes: 15 additions & 5 deletions src/gui/clips/ClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "KeyboardShortcuts.h"
#include "lmms_math.h"
#include "MidiClipView.h"
#include "PatternEditor.h"
#include "PatternClip.h"
#include "PatternStore.h"
#include "Song.h"
Expand Down Expand Up @@ -119,6 +120,8 @@ ClipView::ClipView( Clip * clip,
connect( m_clip, SIGNAL(lengthChanged()),
this, SLOT(updateLength()));
connect(getGUI()->songEditor()->m_editor, &SongEditor::pixelsPerBarChanged, this, &ClipView::updateLength);
connect(getGUI()->patternEditor()->m_editor, &PatternEditor::zoomLevelChanged, this, &ClipView::updateLength);
connect(getGUI()->patternEditor()->m_editor, &PatternEditor::offsetValueChanged, this, &ClipView::updatePosition);
connect( m_clip, SIGNAL(positionChanged()),
this, SLOT(updatePosition()));
connect( m_clip, SIGNAL(destroyedClip()), this, SLOT(close()));
Expand Down Expand Up @@ -314,7 +317,7 @@ void ClipView::updateLength()
{
if( fixedClips() )
{
setFixedWidth( parentWidget()->width() );
setFixedWidth(parentWidget()->width() * getGUI()->patternEditor()->zoomLevel());
}
else
{
Expand All @@ -337,10 +340,17 @@ void ClipView::updateLength()
*/
void ClipView::updatePosition()
{
m_trackView->getTrackContentWidget()->changePosition();
// moving a Clip can result in change of song-length etc.,
// therefore we update the track-container
m_trackView->trackContainerView()->update();
if (fixedClips())
{
move(-parentWidget()->width() * getGUI()->patternEditor()->horizontalScrollValue(), 0);
}
else
{
m_trackView->getTrackContentWidget()->changePosition();
// moving a Clip can result in change of song-length etc.,
// therefore we update the track-container
m_trackView->trackContainerView()->update();
}
}

void ClipView::selectColor()
Expand Down
45 changes: 38 additions & 7 deletions src/gui/clips/MidiClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ void MidiClipView::wheelEvent(QWheelEvent * we)
const auto pos = we->position().toPoint();
if(m_clip->m_clipType == MidiClip::Type::BeatClip &&
(fixedClips() || pixelsPerBar() >= 96) &&
pos.y() > height() - m_stepBtnOff.height())
pos.y() > height() - m_stepBtnOff.height() &&
!(we->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier)))
{
// get the step number that was wheeled on and
// do calculations in floats to prevent rounding errors...
Expand Down Expand Up @@ -822,16 +823,46 @@ void MidiClipView::paintEvent( QPaintEvent * )
const int lineSize = 3;
p.setPen( c.darker( 200 ) );

for(float t = (offset % TimePos::ticksPerBar()) * pixelsPerBar / TimePos::ticksPerBar(); t < m_clip->length(); t += pixelsPerBar)
if (fixedClips())
{
p.drawLine( x_base + t - 1,
// We don't draw the bar lines the same way in the pattern editor as the view's lenght and position are
// modified arbitrarily by zoom and scroll values, and the clip always start at t=0
const int steps = std::max(1, m_clip->m_steps);
const int w = width() - 2 * BORDER_WIDTH;

for (int step = TimePos::stepsPerBar(); step < steps; step += TimePos::stepsPerBar())
{
p.drawLine(
BORDER_WIDTH + step * w / static_cast<float>(steps),
BORDER_WIDTH,
BORDER_WIDTH + step * w / static_cast<float>(steps),
BORDER_WIDTH + lineSize
);
p.drawLine(
BORDER_WIDTH + step * w / static_cast<float>(steps),
rect().bottom() - (lineSize + BORDER_WIDTH),
BORDER_WIDTH + step * w / static_cast<float>(steps),
rect().bottom() - BORDER_WIDTH
);
}
}
else
{
for(float t = (offset % TimePos::ticksPerBar()) * pixelsPerBar / TimePos::ticksPerBar(); t < m_clip->length(); t += pixelsPerBar)
{
p.drawLine(
x_base + t - 1,
BORDER_WIDTH,
x_base + t - 1,
BORDER_WIDTH + lineSize
);
p.drawLine(
x_base + t - 1,
BORDER_WIDTH + lineSize );
p.drawLine( x_base + t - 1,
rect().bottom() - ( lineSize + BORDER_WIDTH ),
rect().bottom() - (lineSize + BORDER_WIDTH),
x_base + t - 1,
rect().bottom() - BORDER_WIDTH );
rect().bottom() - BORDER_WIDTH
);
}
}

// clip name
Expand Down
Loading
Loading