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

Remove instrument track window caching to fix related bugs #5808

Merged
merged 3 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 3 additions & 6 deletions include/InstrumentTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,6 @@ class InstrumentTrackView : public TrackView
return m_midiMenu;
}

void freeInstrumentTrackWindow();

static void cleanupWindowCache();

// Create a menu for assigning/creating channels for this track
QMenu * createFxMenu( QString title, QString newFxLabel ) override;

Expand All @@ -349,12 +345,12 @@ private slots:
void assignFxLine( int channelIndex );
void createFxLine();

void handleConfigChange(QString cls, QString attr, QString value);


private:
InstrumentTrackWindow * m_window;

static QQueue<InstrumentTrackWindow *> s_windowCache;
PhysSong marked this conversation as resolved.
Show resolved Hide resolved

// widgets in track-settings-widget
TrackLabelButton * m_tlb;
Knob * m_volumeKnob;
Expand Down Expand Up @@ -482,6 +478,7 @@ protected slots:
PianoView * m_pianoView;

friend class InstrumentView;
friend class InstrumentTrackView;

} ;

Expand Down
2 changes: 0 additions & 2 deletions src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,6 @@ void Song::clearProject()
Engine::projectJournal()->clearJournal();

Engine::projectJournal()->setJournalling( true );

InstrumentTrackView::cleanupWindowCache();
}


Expand Down
1 change: 0 additions & 1 deletion src/gui/GuiApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ GuiApplication::GuiApplication()

GuiApplication::~GuiApplication()
{
InstrumentTrackView::cleanupWindowCache();
s_instance = nullptr;
}

Expand Down
107 changes: 23 additions & 84 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
const int INSTRUMENT_WIDTH = 254;
const int INSTRUMENT_HEIGHT = INSTRUMENT_WIDTH;
const int PIANO_HEIGHT = 80;
const int INSTRUMENT_WINDOW_CACHE_SIZE = 8;


// #### IT:
Expand Down Expand Up @@ -951,9 +950,6 @@ void InstrumentTrack::autoAssignMidiDevice(bool assign)
// #### ITV:


QQueue<InstrumentTrackWindow *> InstrumentTrackView::s_windowCache;



InstrumentTrackView::InstrumentTrackView( InstrumentTrack * _it, TrackContainerView* tcv ) :
TrackView( _it, tcv ),
Expand All @@ -975,6 +971,10 @@ InstrumentTrackView::InstrumentTrackView( InstrumentTrack * _it, TrackContainerV
connect( _it, SIGNAL( nameChanged() ),
m_tlb, SLOT( update() ) );

connect( ConfigManager::inst(), SIGNAL( valueChanged( QString, QString, QString ) ),
this, SLOT( handleConfigChange( QString, QString, QString ) ),
Qt::QueuedConnection );
PhysSong marked this conversation as resolved.
Show resolved Hide resolved

// creation of widgets for track-settings-widget
int widgetWidth;
if( ConfigManager::inst()->value( "ui",
Expand Down Expand Up @@ -1066,7 +1066,8 @@ InstrumentTrackView::InstrumentTrackView( InstrumentTrack * _it, TrackContainerV

InstrumentTrackView::~InstrumentTrackView()
{
freeInstrumentTrackWindow();
delete m_window;
Copy link
Contributor

Choose a reason for hiding this comment

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

What about using unique_ptr instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's out of scope, but it's doable.

m_window = nullptr;

delete model()->m_midiPort.m_readablePortsMenu;
delete model()->m_midiPort.m_writablePortsMenu;
Expand Down Expand Up @@ -1119,89 +1120,26 @@ void InstrumentTrackView::assignFxLine(int channelIndex)



// TODO: Add windows to free list on freeInstrumentTrackWindow.
// But, don't NULL m_window or disconnect signals. This will allow windows
// that are being show/hidden frequently to stay connected.
void InstrumentTrackView::freeInstrumentTrackWindow()
InstrumentTrackWindow * InstrumentTrackView::getInstrumentTrackWindow()
{
if( m_window != NULL )
if (!m_window)
{
m_lastPos = m_window->parentWidget()->pos();

if( ConfigManager::inst()->value( "ui",
"oneinstrumenttrackwindow" ).toInt() ||
s_windowCache.count() < INSTRUMENT_WINDOW_CACHE_SIZE )
{
model()->setHook( NULL );
m_window->setInstrumentTrackView( NULL );
m_window->parentWidget()->hide();
m_window->updateInstrumentView();
s_windowCache << m_window;
}
else
{
delete m_window;
}

m_window = NULL;
m_window = new InstrumentTrackWindow(this);
}
}




void InstrumentTrackView::cleanupWindowCache()
{
while( !s_windowCache.isEmpty() )
{
delete s_windowCache.dequeue();
}
return m_window;
}




InstrumentTrackWindow * InstrumentTrackView::getInstrumentTrackWindow()
void InstrumentTrackView::handleConfigChange(QString cls, QString attr, QString value)
{
if( m_window != NULL )
{
}
else if( !s_windowCache.isEmpty() )
// When one instrument track window mode is turned on,
// close windows except last opened one.
if (cls == "ui" && attr == "oneinstrumenttrackwindow" && value.toInt())
{
m_window = s_windowCache.dequeue();

m_window->setInstrumentTrackView( this );
m_window->setModel( model() );
m_window->updateInstrumentView();
model()->setHook( m_window );

if( ConfigManager::inst()->
value( "ui", "oneinstrumenttrackwindow" ).toInt() )
{
s_windowCache << m_window;
}
else if( m_lastPos.x() > 0 || m_lastPos.y() > 0 )
{
m_window->parentWidget()->move( m_lastPos );
}
m_tlb->setChecked(m_window && m_window == topLevelInstrumentTrackWindow());
}
else
{
m_window = new InstrumentTrackWindow( this );
if( ConfigManager::inst()->
value( "ui", "oneinstrumenttrackwindow" ).toInt() )
{
// first time, an InstrumentTrackWindow is opened
s_windowCache << m_window;
}
}

return m_window;
}




void InstrumentTrackView::dragEnterEvent( QDragEnterEvent * _dee )
{
InstrumentTrackWindow::dragEnterEventGeneric( _dee );
Expand All @@ -1225,12 +1163,15 @@ void InstrumentTrackView::dropEvent( QDropEvent * _de )

void InstrumentTrackView::toggleInstrumentWindow( bool _on )
{
getInstrumentTrackWindow()->toggleVisibility( _on );

if( !_on )
if (_on && ConfigManager::inst()->value("ui", "oneinstrumenttrackwindow").toInt())
{
freeInstrumentTrackWindow();
if (topLevelInstrumentTrackWindow())
{
topLevelInstrumentTrackWindow()->m_itv->m_tlb->setChecked(false);
}
}

getInstrumentTrackWindow()->toggleVisibility( _on );
}


Expand Down Expand Up @@ -1547,11 +1488,9 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) :

InstrumentTrackWindow::~InstrumentTrackWindow()
{
InstrumentTrackView::s_windowCache.removeAll( this );

delete m_instrumentView;

if( gui->mainWindow()->workspace() )
if (parentWidget())
Copy link
Member Author

Choose a reason for hiding this comment

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

This is to prevent crashes on closing.

{
parentWidget()->hide();
parentWidget()->deleteLater();
Expand Down