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

MIDI Export feature (issue #258) #1686

Merged
merged 6 commits into from
Feb 7, 2015
Merged

Conversation

mohamed--abdel-maksoud
Copy link
Contributor

Background: #258

This is an implementation of a basic MIDI export feature in LMMS.

Remarks:

  • only instrument tracks are considered.
  • LMMS tracks are mapped 1-to-1 to MIDI tracks.

Your feedback is welcome.

@diizy
Copy link
Contributor

diizy commented Jan 24, 2015

Why is there python code in this commit?

Not every platform comes with python. That's an additional dependency that seems unnecessary to add. I don't think we can merge this as it is now...

It would be a better idea to implement this as a file-export plugin. At the very least, get rid of the python...

@mohamed--abdel-maksoud
Copy link
Contributor Author

The python script is a standalone utility to convert mmp files to MIDI. The LMMS program has no dependency on it.

@diizy
Copy link
Contributor

diizy commented Jan 24, 2015

If it's standalone, then I'm not sure if it should be in our main source tree... maybe a separate repository for it would be a better idea.

@@ -0,0 +1,317 @@
#ifndef __MIDIFILE_HPP
#define __MIDIFILE_HPP
Copy link
Contributor

Choose a reason for hiding this comment

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

leading underscores in header guards is a no-no. Also, we don't use the .hpp extension, all our headers are .h

@mohamed--abdel-maksoud
Copy link
Contributor Author

cool, I'll make a new pull request with the script removed.

@diizy
Copy link
Contributor

diizy commented Jan 24, 2015

Also, it'd be better to implement this functionality as a plugin. Look at how midi-import is implemented, IIRC it's done as a file-import plugin. Midi-export can be implemented as a file-export-plugin.

This improves modularity of code and makes it easier to change and develop things later...

@mohamed--abdel-maksoud
Copy link
Contributor Author

sounds good, yet I've no more time to invest in LMMS atm.

@eagles051387
Copy link

You also do not need to create another pull request. You can make the
changes that were suggested above and commit them and the pull request
automatically gets updated as well.

On Sun, Jan 25, 2015 at 12:41 AM, Mohamed Abdel Maksoud <
notifications@github.com> wrote:

sounds good, yet I've not more time to invest in LMMS atm.


Reply to this email directly or view it on GitHub
#1686 (comment).

Jonathan Aquilina

@mohamed--abdel-maksoud
Copy link
Contributor Author

Thanks eagles, I noticed my commits appear here.
I've already committed the changes I can do now.

@tresf
Copy link
Member

tresf commented Jan 29, 2015

@mohamed--abdel-maksoud this feature would be tremendous to have ready for stable-1.2 testing.

A few things... Travis seems to have some win32 compilation errors as seen here: jobs/48204778#L4905.

As @diizy mentioned, we would also need the code moved to plugins/MidiExport to remain consistent with our plugins architecture. Here's an example: plugins/MidiImport

@mohamed--abdel-maksoud
Copy link
Contributor Author

@tresf the error on win32 is trivial, I just fixed it.
I'll start looking at refactoring code as a plugin from next week if it is too necessary.

@dednikko
Copy link

I apologize if this is seen as too far off topic, but:

@mohamed, THANK YOU! I know that this can be a pain to redo, and I want to
thank you for working on it.

From what I see, it would be best implemented as a plugin.

I just want you to know I am very excited to see this feature happen. You
will make a lot of users extremely happy!

/tangent
On Jan 29, 2015 3:26 PM, "Mohamed Abdel Maksoud" notifications@github.com
wrote:

@tresf https://github.com/tresf the error on win32 is trivial, I just
fixed it.
I'll start looking at refactoring code as a plugin from next week if it is
too necessary.


Reply to this email directly or view it on GitHub
#1686 (comment).

@mohamed--abdel-maksoud
Copy link
Contributor Author

Thanks @dednikko (: I've been looking to see this feature implemented for some time, too.

@unfa
Copy link
Contributor

unfa commented Feb 1, 2015

This is going to be a serious improvement to LMMS, thank you for getting
your hands dirty to do it, Mohamed! :)
24 sty 2015 23:59 "Mohamed Abdel Maksoud" notifications@github.com
napisał(a):

Background: #258 #258

This is an implementation of a basic MIDI export feature in LMMS.

Remarks:

  • only instrument tracks are considered.
  • LMMS tracks are mapped 1-to-1 to MIDI tracks.

Your feedback is welcome.

You can view, comment on, or merge this pull request online at:

#1686
Commit Summary

  • standalone utility to convert mmp to midi
  • gui change and stub for midi output
  • Merge remote-tracking branch 'upstream/master'
  • c++ header to abstract MIDI format
  • first working version: Export Midi feature maps instrument tracks to
    equivalent MIDI tracks
  • fixing output file name
  • Merge remote-tracking branch 'upstream/master'

File Changes

Patch Links:


Reply to this email directly or view it on GitHub
#1686.

@badosu
Copy link
Contributor

badosu commented Feb 3, 2015

Hi @mohamed--abdel-maksoud, it's not exactly required but could you try to squash some commits together and rename others?

Keeping our git history sane is very important so that we are able to track regressions in an easy way.

There is a nice tutorial on how to use git rebase -i to achieve this. Thanks for the contribution, let me know if you have any questions.

Some references:

midiout.writeRawData((char *)buffer, size);

// midi tracks
foreach( Track* track, tracks )
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we can modularize this so that we are able to export individual tracks in the future?

@mohamed--abdel-maksoud
Copy link
Contributor Author

@badosu I just pushed a change where midi export is a plugin, I think this modularizes the part in question.
I agree, the commits are quite messy so far, I'll try to organize them.

qDebug() << "failed to load midi export filter!";
return;
}
exf->tryExport(tracks, Engine::getSong()->getTempo(), export_filename);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! In case we need to implement single track MIDI export feature this will come handy.

@mohamed--abdel-maksoud mohamed--abdel-maksoud force-pushed the master branch 4 times, most recently from 34031b2 to d6349c3 Compare February 3, 2015 23:25
@mohamed--abdel-maksoud
Copy link
Contributor Author

it builds fine now, I tried to organize the commits but I guess I didn't do it right. If this is an issue I'll create a new fork and commit the changes anew.

@badosu
Copy link
Contributor

badosu commented Feb 4, 2015

Hi mohamed, I noticed something has happened there and the history got all messed up.

So I took all your changes and created a patch file for them, it's here: https://gist.github.com/badosu/120eaf72dc3847049ce0.

I made some commands so that you are able to restore your changes to an incorrupt state:

git checkout upstream/master
git checkout -b add-midi-export
curl https://gist.githubusercontent.com/badosu/120eaf72dc3847049ce0/raw/35020a3c0d325d451864b5f68621ce9558419e16/gistfile1.diff | git apply

Now you should be able to add files and commit them the way you want and open a new PR with everything fixed. Or you can fix the current PR as well.

@mohamed--abdel-maksoud
Copy link
Contributor Author

thanks @badosu, I applied the commands, merged them and pushed to master, I'm not sure though how to delete my prior commits (I'm used to svn, so git can be challenging at times)

@eagles051387
Copy link

you can do a git reset which should clear out those other commits.

On Wed, Feb 4, 2015 at 1:50 PM, Mohamed Abdel Maksoud <
notifications@github.com> wrote:

thanks @badosu https://github.com/badosu, I applied the commands,
merged them and pushed to master, I'm not sure though how to delete my
prior commits (I'm used to svn, so git can be challenging at times)


Reply to this email directly or view it on GitHub
#1686 (comment).

Jonathan Aquilina

@mohamed--abdel-maksoud
Copy link
Contributor Author

thanks @eagles051387 , git reset seems to do the trick

// events are sorted by their time
inline bool operator < (const Event& b) const {
if (this->time < b.time) return true;
#if 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a little ignorant about C++, what does this mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh I was experimenting with the ordering of MIDI events, basically any thing between #if 0 and #endif is discarded, this part could be cleaned.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clean this up?

Remember that you don't have to create additional commits, after you've done your changes and added them you can use git commit --amend instead of the regular one to ammend your changes to the last commit.

You'll have to push with -f later. This is not an issue since this branch is only yours.

@badosu
Copy link
Contributor

badosu commented Feb 4, 2015

Really nice work @mohamed--abdel-maksoud, let me test this feature.

@badosu
Copy link
Contributor

badosu commented Feb 4, 2015

@mohamed--abdel-maksoud It's missing the changes on the src/core/Song.cpp file.

See https://gist.github.com/badosu/120eaf72dc3847049ce0#file-gistfile1-diff-L684

@mohamed--abdel-maksoud
Copy link
Contributor Author

@badosu sorry, the cmake cache deceived me, the latest push should restore the changes

{
QDomElement note = nn.toElement();
if (note.attribute("len", "0") == "0" || note.attribute("vol", "0") == "0") continue;
#if 0
Copy link
Contributor

Choose a reason for hiding this comment

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

@mohamed--abdel-maksoud Another one here...

@badosu
Copy link
Contributor

badosu commented Feb 4, 2015

@mohamed--abdel-maksoud I am seeing some seemingly debug messages, is it related to this PR?

2015-02-04-201819_151x320_scrot


void MidiExport::error()
{
//qDebug() << "MidiExport error: " << m_error ;
Copy link
Contributor

Choose a reason for hiding this comment

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

@mohamed--abdel-maksoud I guess you wanted to implement something here?

@mohamed--abdel-maksoud
Copy link
Contributor Author

@badosu yes, I cleaned that locally, let me know if there're more of such small fixes before I group them in one commit

@badosu
Copy link
Contributor

badosu commented Feb 4, 2015

So, I just exported a big track to MIDI and it looks like it works! (https://github.com/SecondFlight/lmms/raw/master/data/projects/CoolSongs/Greippi%20-%20Krem%20Kaakkuja%20%28Second%20Flight%20Remix%29.mmpz)

There are some possible improvements though, it looks like everything is Grand Piano and we may be able to extract some information from the tracks and changing their type, but should be a posterior improvement.

Also another possible improvement can be on how we show the "Export to MIDI" button, we can show this as a new option on the already existent Export Panel instead of a File menu option, that's arguable though.

I tried opening the generated MIDI file on Drumstick (http://sourceforge.net/projects/drumstick/) and it's crashing, I don't know if this is a problem with the file exactly.

Opening on a normal audio player with MIDI support works.

@mohamed--abdel-maksoud
Copy link
Contributor Author

@badosu Thanks for trying out the feature Amadeus! I just tested with this song and it seems to trigger a bug (the output MIDI has some out of range notes), I'll look into this one of the following days.

@badosu
Copy link
Contributor

badosu commented Feb 4, 2015

Thanks for following up Mohamed!

@diizy
Copy link
Contributor

diizy commented Feb 7, 2015

Things look good here, good work on modularizing the code

diizy added a commit that referenced this pull request Feb 7, 2015
@diizy diizy merged commit b1a007b into LMMS:master Feb 7, 2015
@badosu
Copy link
Contributor

badosu commented Feb 7, 2015

@diizy I was still expecting some feedback from @mohamed--abdel-maksoud, but I guess he can send a PR later to address these issues.

@mohamed--abdel-maksoud
Copy link
Contributor Author

@diizy @badosu the latest couple of commits should fix the bug: for some reason the song contains notes with negative durations or volumes above the maximum allowed in MIDI, now such notes are trimmed or discarded.

@tresf tresf mentioned this pull request Feb 23, 2015
26 tasks
@tresf tresf mentioned this pull request Apr 4, 2015
@Umcaruje
Copy link
Member

Umcaruje commented Jul 3, 2015

@mohamed--abdel-maksoud it seems that commits mohamed--abdel-maksoud@e048035 and mohamed--abdel-maksoud@9a40363 were added to your branch after this PR was merged and closed, so they aren't in the upstream master branch. Could you issue a new PR that adds these commits?

@zonkmachine
Copy link
Member

@mohamed--abdel-maksoud it seems that commits mohamed--abdel-maksoud/lmms@e048035 and mohamed--abdel-maksoud/lmms@9a40363 were added to your branch after this PR was merged and closed, so they aren't in the upstream master branch. Could you issue a new PR that adds these commits?

@mohamed--abdel-maksoud @Umcaruje These commits seem to be unmerged still. I can't test them right now but I cherry-picked them and they compile fine.

@zonkmachine
Copy link
Member

@Umcaruje @mohamed--abdel-maksoud
I tested the export function with and without these forgotten commits.

Three tracks exported and the resulting track imported below. The output is the correct notes
but piled together in one track.

midiscrambled

Here is the same project exported with commits commits mohamed--abdel-maksoud/lmms@e048035 and mohamed--abdel-maksoud/lmms@9a40363.
The notes are somewhat scambled and there seem to be duplicate patterns in there.

midi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants