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 save/load of PianoRoll marked semitones #5146

Merged
merged 1 commit into from
Sep 14, 2019
Merged
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
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