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

Add Playhead and Timeline to Pattern Editor #7794

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
Binary file added data/themes/default/step_btn_highlight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions include/MidiClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class LMMS_EXPORT MidiClip : public Clip
return m_clipType;
}

int steps() const
{
return m_steps;
}


// next/previous track based on position in the containing track
MidiClip * previousMidiClip() const;
Expand Down
1 change: 1 addition & 0 deletions include/MidiClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ protected slots:
QPixmap m_stepBtnOn200 = embed::getIconPixmap("step_btn_on_200");
QPixmap m_stepBtnOff = embed::getIconPixmap("step_btn_off");
QPixmap m_stepBtnOffLight = embed::getIconPixmap("step_btn_off_light");
QPixmap m_stepBtnHighlight = embed::getIconPixmap("step_btn_highlight");

MidiClip* m_clip;
QPixmap m_paintPixmap;
Expand Down
7 changes: 7 additions & 0 deletions include/PatternEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace gui
{

class ComboBox;
class TimeLineWidget;


class PatternEditor : public TrackContainerView
Expand All @@ -62,13 +63,19 @@ public slots:
void addSampleTrack();
void addAutomationTrack();
void cloneClip();
void updateMaxSteps();

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

private:
PatternStore* m_ps;
TimeLineWidget * m_timeLine;
int m_trackHeadWidth;
int m_maxSteps;
void makeSteps( bool clone );
};

Expand Down
2 changes: 2 additions & 0 deletions include/PatternStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public slots:
void updateComboBox();
void currentPatternChanged();

signals:
void trackUpdated();

private:
ComboBoxModel m_patternComboBoxModel;
Expand Down
6 changes: 6 additions & 0 deletions include/TrackView.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class TrackView : public QWidget, public ModelView, public JournallingObject
return m_track;
}

const std::vector<ClipView*>& getClipViews()
{
return m_clipViews;
}

inline TrackContainerView* trackContainerView()
{
return m_trackContainerView;
Expand Down Expand Up @@ -151,6 +156,7 @@ public slots:

Track * m_track;
TrackContainerView * m_trackContainerView;
std::vector<ClipView*> m_clipViews;

TrackOperationsWidget m_trackOperationsWidget;
QWidget m_trackSettingsWidget;
Expand Down
1 change: 1 addition & 0 deletions src/core/PatternStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ void PatternStore::updatePatternTrack(Clip* clip)
{
t->dataChanged();
}
emit trackUpdated();
}


Expand Down
10 changes: 10 additions & 0 deletions src/gui/clips/MidiClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ void MidiClipView::paintEvent( QPaintEvent * )
QPixmap stepon200;
QPixmap stepoff;
QPixmap stepoffl;
QPixmap stephighlight;
const int steps = std::max(1, m_clip->m_steps);
const int w = width() - 2 * BORDER_WIDTH;

Expand All @@ -472,6 +473,8 @@ void MidiClipView::paintEvent( QPaintEvent * )
= m_stepBtnOff.scaled(w / steps, m_stepBtnOff.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
stepoffl = m_stepBtnOffLight.scaled(
w / steps, m_stepBtnOffLight.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
stephighlight = m_stepBtnHighlight.scaled(
w / steps, m_stepBtnHighlight.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);

for (int it = 0; it < steps; it++) // go through all the steps in the beat clip
{
Expand All @@ -481,6 +484,9 @@ void MidiClipView::paintEvent( QPaintEvent * )
const int x = BORDER_WIDTH + static_cast<int>(it * w / steps);
const int y = BeatStepButtonOffset;

const bool isAtPlayPos = Engine::getSong()->getPlayPos(Song::PlayMode::Pattern) * TimePos::stepsPerBar() / TimePos::ticksPerBar() == it
&& Engine::getSong()->playMode() == Song::PlayMode::Pattern;

if (n)
{
const int vol = n->getVolume();
Expand All @@ -498,6 +504,10 @@ void MidiClipView::paintEvent( QPaintEvent * )
{
p.drawPixmap(x, y, stepoff);
}
if (isAtPlayPos)
{
p.drawPixmap(x, y, stephighlight);
}
} // end for loop

// draw a transparent rectangle over muted clips
Expand Down
52 changes: 51 additions & 1 deletion src/gui/editors/PatternEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "PatternEditor.h"

#include <QAction>
#include <QVBoxLayout>

#include "ClipView.h"
#include "ComboBox.h"
Expand All @@ -35,6 +36,7 @@
#include "PatternTrack.h"
#include "Song.h"
#include "StringPairDrag.h"
#include "TimeLineWidget.h"
#include "TrackView.h"

#include "MidiClip.h"
Expand All @@ -46,9 +48,24 @@ namespace lmms::gui

PatternEditor::PatternEditor(PatternStore* ps) :
TrackContainerView(ps),
m_ps(ps)
m_ps(ps),
m_trackHeadWidth(ConfigManager::inst()->value("ui", "compacttrackbuttons").toInt() == 1
? DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT + TRACK_OP_WIDTH_COMPACT
: DEFAULT_SETTINGS_WIDGET_WIDTH + TRACK_OP_WIDTH),
m_maxSteps(TimePos::stepsPerBar())
{
setModel(ps);

m_timeLine = new TimeLineWidget(m_trackHeadWidth, 32, pixelsPerBar(),
Engine::getSong()->getPlayPos(Song::PlayMode::Pattern),
Engine::getSong()->getTimeline(Song::PlayMode::Pattern),
m_currentPosition, Song::PlayMode::Pattern, this
);
connect(m_timeLine, &TimeLineWidget::positionChanged, this, &PatternEditor::updatePosition);
static_cast<QVBoxLayout*>( layout() )->insertWidget( 0, m_timeLine );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we need the static_cast here?

Suggested change
static_cast<QVBoxLayout*>( layout() )->insertWidget( 0, m_timeLine );
layout()->insertWidget(0, m_timeLine);


connect(m_ps, &PatternStore::trackUpdated,
this, &PatternEditor::updateMaxSteps);
}


Expand Down Expand Up @@ -79,6 +96,7 @@ void PatternEditor::removeSteps()
p->removeSteps();
}
}
updateMaxSteps();
}


Expand Down Expand Up @@ -118,6 +136,7 @@ void PatternEditor::saveSettings(QDomDocument& doc, QDomElement& element)
void PatternEditor::loadSettings(const QDomElement& element)
{
MainWindow::restoreWidgetState(parentWidget(), element);
updateMaxSteps();
}


Expand Down Expand Up @@ -160,18 +179,47 @@ void PatternEditor::dropEvent(QDropEvent* de)
{
TrackContainerView::dropEvent( de );
}
updateMaxSteps();
}


void PatternEditor::resizeEvent(QResizeEvent* re)
{
updatePixelsPerBar();
}


void PatternEditor::updatePosition()
{
//realignTracks();
for (const auto& trackView : trackViews())
{
trackView->update();
}
emit positionChanged( m_currentPosition );
}

void PatternEditor::updatePixelsPerBar()
{
setPixelsPerBar((width() - m_trackHeadWidth) * TimePos::stepsPerBar() / m_maxSteps);
m_timeLine->setPixelsPerBar(pixelsPerBar());
}

void PatternEditor::updateMaxSteps()
{
const TrackContainer::TrackList& tl = model()->tracks();

m_maxSteps = 0;
for (const auto& track : tl)
{
if (track->type() == Track::Type::Instrument)
{
auto p = static_cast<MidiClip*>(track->getClip(m_ps->currentPattern()));
m_maxSteps = std::max(m_maxSteps, p->steps());
}
}
updatePixelsPerBar();
}


void PatternEditor::makeSteps( bool clone )
Expand All @@ -192,6 +240,7 @@ void PatternEditor::makeSteps( bool clone )
}
}
}
updateMaxSteps();
}

// Creates a clone of the current pattern track with the same content, but no clips in the song editor
Expand Down Expand Up @@ -285,6 +334,7 @@ PatternEditorWindow::PatternEditorWindow(PatternStore* ps) :

connect(&ps->m_patternComboBoxModel, SIGNAL(dataChanged()),
m_editor, SLOT(updatePosition()));
connect(&ps->m_patternComboBoxModel, &ComboBoxModel::dataChanged, m_editor, &PatternEditor::updateMaxSteps);

auto viewNext = new QAction(this);
connect(viewNext, SIGNAL(triggered()), m_patternComboBox, SLOT(selectNext()));
Expand Down
1 change: 1 addition & 0 deletions src/gui/tracks/TrackView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ void TrackView::createClipView( Clip * clip )
tv->setSelected( true );
}
clip->selectViewOnCreate( false );
m_clipViews.push_back(tv);
}


Expand Down
Loading