Skip to content

Commit

Permalink
Add save/load of PianoRoll marked semitones (LMMS#5146)
Browse files Browse the repository at this point in the history
  • Loading branch information
Veratil authored and Reflexe committed Sep 14, 2019
1 parent f452516 commit f45d42b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class PianoRoll : public QWidget
void setCurrentPattern( Pattern* newPattern );
void setGhostPattern( Pattern* newPattern );
void loadGhostNotes( const QDomElement & de );
void loadMarkedSemiTones(const QDomElement & de);

inline void stopRecording()
{
Expand Down
42 changes: 41 additions & 1 deletion src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*
*/

#include "PianoRoll.h"

#include <QApplication>
#include <QClipboard>
#include <QKeyEvent>
Expand All @@ -46,7 +48,6 @@
#include "AutomationEditor.h"
#include "ActionGroup.h"
#include "ConfigManager.h"
#include "PianoRoll.h"
#include "BBTrackContainer.h"
#include "Clipboard.h"
#include "ComboBox.h"
Expand Down Expand Up @@ -655,6 +656,32 @@ void PianoRoll::clearGhostPattern()
}


void PianoRoll::loadMarkedSemiTones(const QDomElement & de)
{
// clear marked semitones to prevent leftover marks
m_markedSemiTones.clear();
if (de.isElement())
{
QDomNode node = de.firstChild();
while (!node.isNull())
{
bool ok;
int key = node.toElement().attribute(
QString("key"), QString("-1")).toInt(&ok, 10);
if (ok && key >= 0)
{
m_markedSemiTones.append(key);
}
node = node.nextSibling();
}
}
// from markSemiTone, required otherwise marks will not show
std::sort(m_markedSemiTones.begin(), m_markedSemiTones.end(), std::greater<int>());
QList<int>::iterator new_end = std::unique(m_markedSemiTones.begin(), m_markedSemiTones.end());
m_markedSemiTones.erase(new_end, m_markedSemiTones.end());
}


void PianoRoll::setCurrentPattern( Pattern* newPattern )
{
if( hasValidPattern() )
Expand Down Expand Up @@ -4697,6 +4724,18 @@ void PianoRollWindow::saveSettings( QDomDocument & doc, QDomElement & de )
de.appendChild( ghostNotesRoot );
}

if (m_editor->m_markedSemiTones.length() > 0)
{
QDomElement markedSemiTonesRoot = doc.createElement("markedSemiTones");
for (int ix = 0; ix < m_editor->m_markedSemiTones.size(); ++ix)
{
QDomElement semiToneNode = doc.createElement("semiTone");
semiToneNode.setAttribute("key", m_editor->m_markedSemiTones.at(ix));
markedSemiTonesRoot.appendChild(semiToneNode);
}
de.appendChild(markedSemiTonesRoot);
}

MainWindow::saveWidgetState( this, de );
}

Expand All @@ -4706,6 +4745,7 @@ void PianoRollWindow::saveSettings( QDomDocument & doc, QDomElement & de )
void PianoRollWindow::loadSettings( const QDomElement & de )
{
m_editor->loadGhostNotes( de.firstChildElement("ghostnotes") );
m_editor->loadMarkedSemiTones(de.firstChildElement("markedSemiTones"));

MainWindow::restoreWidgetState( this, de );
}
Expand Down

0 comments on commit f45d42b

Please sign in to comment.