Skip to content

Commit

Permalink
Fix missing icons for some instruments (LMMS#7132)
Browse files Browse the repository at this point in the history
Revert some of the changes made in commit 88e0e94. The underlying idea was that the `InstrumentTrackView` should be responsible for assigning the icon that's shown by its `TrackLabelButton`. However, this does not work because in some cases the `InstrumentTrack` that's passed into `InstrumentTrackView::determinePixmap` does not have an `Instrument` assigned. This in turn seems to be caused due to initalizations that are running in parallel in different threads.

Here are the steps to reproduce the threading problem (line numbers refer to commit 360254f):
1. Set a break point in line 1054 of `InstrumentTrack`, i.e. the line in `InstrumentTrack::loadInstrument` where `m_instrument` is being assigned to.
2. Set a break point in `InstrumentTrackView::determinePixmap`, e.g. inside of the first if statement.
3. Drop an instance of "Sf2 Player" onto the Song Editor.
4. The first break point in `InstrumentTrack` is hit in a thread called "lmms::Instrumen" (shown like that in my debugger). Try to step over it.
5. The second break point in `InstrumentTrackView` now gets hit before the code is stepped over. This time we are in the thread called "lmms". I guess this is the GUI main thread.
6. Continue execution.

If you now switch to the application then the icon is shown. I guess the debugger is halted long enough in the main thread so that the InstrumentTrack gets an instrument assigned in another thread.

If you delete/disable the break point in `InstrumentTrack::determinePixmap` and follow the coarse steps above then the icon is not shown because the track has no instrument.

The current fix still delegates to the `InstrumentTrackView` to determine the pixmap in hopes that one day there will be a better solution where the parent component can be fully responsible for its child component.

Fixes LMMS#7116.
  • Loading branch information
michaelgregorius authored Mar 13, 2024
1 parent 37073af commit 04ecf73
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/InstrumentTrackView.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class InstrumentTrackView : public TrackView
// Create a menu for assigning/creating channels for this track
QMenu * createMixerMenu( QString title, QString newMixerLabel ) override;

QPixmap determinePixmap();


protected:
void modelChanged() override;
Expand Down
1 change: 1 addition & 0 deletions include/TrackLabelButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public slots:
void mousePressEvent( QMouseEvent * _me ) override;
void mouseDoubleClickEvent( QMouseEvent * _me ) override;
void mouseReleaseEvent( QMouseEvent * _me ) override;
void paintEvent(QPaintEvent* pe) override;
void resizeEvent( QResizeEvent * _re ) override;

private:
Expand Down
5 changes: 5 additions & 0 deletions src/gui/tracks/InstrumentTrackView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ QMenu * InstrumentTrackView::createMixerMenu(QString title, QString newMixerLabe
return mixerMenu;
}

QPixmap InstrumentTrackView::determinePixmap()
{
return determinePixmap(dynamic_cast<InstrumentTrack*>(getTrack()));
}


QPixmap InstrumentTrackView::determinePixmap(InstrumentTrack* instrumentTrack)
{
Expand Down
11 changes: 11 additions & 0 deletions src/gui/tracks/TrackLabelButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "ConfigManager.h"
#include "embed.h"
#include "InstrumentTrackView.h"
#include "RenameDialog.h"
#include "TrackRenameLineEdit.h"
#include "TrackView.h"
Expand Down Expand Up @@ -178,6 +179,16 @@ void TrackLabelButton::mouseReleaseEvent( QMouseEvent *_me )
}


void TrackLabelButton::paintEvent(QPaintEvent* pe)
{
InstrumentTrackView* instrumentTrackView = dynamic_cast<InstrumentTrackView*>(m_trackView);
if (instrumentTrackView)
{
setIcon(instrumentTrackView->determinePixmap());
}

QToolButton::paintEvent(pe);
}


void TrackLabelButton::resizeEvent(QResizeEvent *_re)
Expand Down

0 comments on commit 04ecf73

Please sign in to comment.