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

Custom note labels in Pianoroll editor #5357

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

komodor1
Copy link

I coded function for custom note labels for Pianoroll editor. Three labels files paths are stored in lmms config file. They can be set in settings -> paths. After setting paths lmms need restart. Then in Pianoroll editor you can select which file you want to use. Function reads labels from .txt files in pattern like attached one. File can't have any empty lines between labels/comments. Empty lines can be only after labels list. Between note number and label must be ONLY ONE space.
In attached screenshots you can see how modifications looks like in Pianoroll and settings.

TODO:
Icon for labels file combo box in Pianoroll editor (currently using Quantize icon),
Only three files support, maybe add some kind of list,
May need some code clean-up and check,

settings
pianoroll
labels.txt

@LmmsBot
Copy link

LmmsBot commented Dec 28, 2019

🤖 Hey, I'm @LmmsBot from github.com/lmms/bot and I made downloads for this pull request, click me to make them magically appear! 🎩

Linux

Windows

🤖
{"platform_name_to_artifacts": {"Linux": [{"artifact": {"title": {"title": "(AppImage)", "platform_name": "Linux"}, "link": {"link": "https://5584-15778896-gh.circle-artifacts.com/0/lmms-1.2.1.584-linux-x86_64.AppImage"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/5584?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}], "Windows": [{"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://5582-15778896-gh.circle-artifacts.com/0/lmms-1.2.1.584-mingw-win32.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/5582?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://5583-15778896-gh.circle-artifacts.com/0/lmms-1.2.1.584-mingw-win64.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/5583?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/hea053kiwjaaiwo7/artifacts/build/lmms-1.2.1-msvc2017-win32.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/29814979"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/8j731w9enf9kro0a/artifacts/build/lmms-1.2.1-msvc2017-win64.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/29814979"}]}, "commit_sha": "d651fda1e55c5ddefd3ced87518a7635b17b87a4"}

Copy link
Contributor

@Veratil Veratil left a comment

Choose a reason for hiding this comment

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

I like the idea!

But I don't like that it's new settings options rather than a specific file you read or not, and you are limited to 3 files instead of the ability to add any number to a single file.

I think this would be much more extensible if it was an XML file that can be read on load (if present in working dir or not). If like this, you can create a tree structure in XML that allows an unlimited number of labels. Granted the file is a little more difficult to write out, but it would be able to be parsed by Qt's loadSettings and not have to be parsed manually. So something like this:

<noteLabels>
  <map name="Drums">
    <label note="65" name="HI-HAT PEDAL" />
    <label note="63" name="(Hi-Hat closed)" />
    ...
  </map>
  <map name="Something something">
    <label note="53" name="whatever" />
    ...
  </map>
  ...
</noteLabels>

Additionally, there are numerous lines here which need to follow the Coding Conventions. Namely if and while blocks, a few spacing issues, and true/false usage over 1/0 are the main issues that I see.

src/gui/editors/PianoRoll.cpp Outdated Show resolved Hide resolved
QTextStream stream(&labelsFile);
QString line = stream.readLine();
QRegExp num("\\d*");
while (!line.isNull()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This happens every paintEvent, which will block on file I/O which can cause freezing of the UI in worse cases. These labels need to be read on LMMS load rather than here and painted from memory.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I've noticed that. I know that is not good way, I'm thinking how to change that.

src/gui/SetupDialog.cpp Show resolved Hide resolved
src/gui/SetupDialog.cpp Outdated Show resolved Hide resolved
src/gui/SetupDialog.cpp Outdated Show resolved Hide resolved
src/gui/SetupDialog.cpp Outdated Show resolved Hide resolved
@komodor1
Copy link
Author

I like the idea!

But I don't like that it's new settings options rather than a specific file you read or not, and you are limited to 3 files instead of the ability to add any number to a single file.

I think this would be much more extensible if it was an XML file that can be read on load (if present in working dir or not). If like this, you can create a tree structure in XML that allows an unlimited number of labels. Granted the file is a little more difficult to write out, but it would be able to be parsed by Qt's loadSettings and not have to be parsed manually.

Thanks for feedback!
XML file is really good idea. But it will be kinda difficult to write maps manually by user, so that's why I used TXT files - easy to write, and very similar to Reaper files. But I see another way. Parse .TXT file, and make tree structure like you proposed. It will be easier to maintain multiple labels maps. Then just add simple list of loaded maps in settings, where you can add or remove maps.
About parsing file in paintEvent. I don't see way how change that. Need some time to think.

@komodor1 komodor1 requested a review from Veratil December 30, 2019 16:30
@qnebra
Copy link

qnebra commented Jan 2, 2020

I think better this will work as another option in pianoroll bar. As this will be more user-friendly UX.

@Veratil
Copy link
Contributor

Veratil commented Jan 3, 2020

XML file is really good idea. But it will be kinda difficult to write maps manually by user, so that's why I used TXT files - easy to write, and very similar to Reaper files. But I see another way. Parse .TXT file, and make tree structure like you proposed. It will be easier to maintain multiple labels maps. Then just add simple list of loaded maps in settings, where you can add or remove maps.

The reason I say XML is twofold. 1) You leverage Qt's XML parser, and don't need to do all this extra manual parsing. 2) Everything in LMMS is saved as an XML file, this being a plaintext file breaks from that and doesn't fit the mold.

About parsing file in paintEvent. I don't see way how change that. Need some time to think.

Read on startup from the file and save in memory.

bool fileCorrect = true;
QFile labelsFile(new_file);
labelsFile.open(QIODevice::ReadOnly);
if (!labelsFile.isOpen()) return ;
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing {}

@@ -128,7 +128,9 @@ static QString getNoteString( int key )
return s_noteStrings[key % 12] + QString::number( static_cast<int>( key / KeysPerOctave ) );
}


bool labelsFile1Correct = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

false instead of 0.

@@ -366,6 +369,32 @@ PianoRoll::PianoRoll() :
connect( &m_quantizeModel, SIGNAL( dataChanged() ),
this, SLOT( quantizeChanged() ) );

// Set up labels model
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting for this entire section to line 397.

@@ -3114,6 +3267,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
}
p.drawLine( WHITE_KEY_WIDTH, y, width(), y );
++key;

Copy link
Contributor

Choose a reason for hiding this comment

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

Extra line added on accident?

{
p.drawPixmap( mousePosition + QPoint( 8, 8 ), *cursor );
}
if (drawCustomLabels)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is the last drawn thing in paintEvent, this will draw over notes at the start of the pattern. Should it?

@@ -4421,6 +4600,50 @@ Note * PianoRoll::noteUnderMouse()
return NULL;
}

bool PianoRoll::labelsPathCorrect( QString labelsPath ){
bool fileCorrect = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

true instead of 1.

@@ -4421,6 +4600,50 @@ Note * PianoRoll::noteUnderMouse()
return NULL;
}

bool PianoRoll::labelsPathCorrect( QString labelsPath ){
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting for this function.

@@ -4515,6 +4738,15 @@ PianoRollWindow::PianoRollWindow() :
m_quantizeComboBox->setFixedSize( 64, 22 );
m_quantizeComboBox->setToolTip( tr( "Quantization") );

// setup labels-stuff
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix whitespace in this area.

@PhysSong
Copy link
Member

XML file is really good idea. But it will be kinda difficult to write maps manually by user, so that's why I used TXT files - easy to write, and very similar to Reaper files. But I see another way. Parse .TXT file, and make tree structure like you proposed. It will be easier to maintain multiple labels maps. Then just add simple list of loaded maps in settings, where you can add or remove maps.

The reason I say XML is twofold. 1) You leverage Qt's XML parser, and don't need to do all this extra manual parsing. 2) Everything in LMMS is saved as an XML file, this being a plaintext file breaks from that and doesn't fit the mold.

We can support both Reaper-compatible plaintext file and standard XML/JSON files. BTW, we need to think about #1857 first.

About parsing file in paintEvent. I don't see way how change that. Need some time to think.

Read on startup from the file and save in memory.

I can see the parsing logic is repeated a few times in many places. We can probably remove the file lists from the settings and let users load them manually(optionally with histories).

@PhysSong PhysSong added the rework required Pull requests which must be reworked to make it able to merge or review label Jan 12, 2021
@PhysSong PhysSong mentioned this pull request Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rework required Pull requests which must be reworked to make it able to merge or review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants