-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b25ed32
export filter for export plugins
mohamed--abdel-maksoud af0f997
midi export plugin
mohamed--abdel-maksoud 8265918
adding midiexport plugin to the list
mohamed--abdel-maksoud 9b7ac3b
cleaning up event ordering function
mohamed--abdel-maksoud 8d5077a
adding menu entry file->export midi
mohamed--abdel-maksoud 2260907
adding exportProjectMidi method, internally uses midiexport plugin
mohamed--abdel-maksoud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* ExportFilter.h - declaration of class ExportFilter, the base-class for all | ||
* file export filters | ||
* | ||
* Copyright (c) 2006-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net> | ||
* | ||
* This file is part of LMMS - http://lmms.io | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program (see COPYING); if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301 USA. | ||
* | ||
*/ | ||
|
||
#ifndef EXPORT_FILTER_H | ||
#define EXPORT_FILTER_H | ||
|
||
#include <QtCore/QFile> | ||
|
||
#include "TrackContainer.h" | ||
#include "Plugin.h" | ||
|
||
|
||
class EXPORT ExportFilter : public Plugin | ||
{ | ||
public: | ||
ExportFilter( const Descriptor * _descriptor ) : Plugin( _descriptor, NULL ) {} | ||
virtual ~ExportFilter() {} | ||
|
||
|
||
virtual bool tryExport( const TrackContainer::TrackList &tracks, int tempo, const QString &filename ) = 0; | ||
protected: | ||
|
||
virtual void saveSettings( QDomDocument &, QDomElement & ) | ||
{ | ||
} | ||
|
||
virtual void loadSettings( const QDomElement & ) | ||
{ | ||
} | ||
|
||
virtual QString nodeName() const | ||
{ | ||
return "import_filter"; | ||
} | ||
|
||
|
||
private: | ||
|
||
} ; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
INCLUDE(BuildPlugin) | ||
|
||
BUILD_PLUGIN(midiexport MidiExport.cpp MidiExport.h MidiFile.hpp | ||
MOCFILES MidiExport.h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
/* | ||
* MidiExport.cpp - support for importing MIDI files | ||
* | ||
* Author: Mohamed Abdel Maksoud <mohamed at amaksoud.com> | ||
* | ||
* This file is part of LMMS - http://lmms.io | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program (see COPYING); if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301 USA. | ||
* | ||
*/ | ||
|
||
|
||
#include <QDomDocument> | ||
#include <QDir> | ||
#include <QApplication> | ||
#include <QMessageBox> | ||
#include <QProgressDialog> | ||
|
||
#include "MidiExport.h" | ||
#include "Engine.h" | ||
#include "TrackContainer.h" | ||
#include "InstrumentTrack.h" | ||
|
||
|
||
extern "C" | ||
{ | ||
|
||
Plugin::Descriptor PLUGIN_EXPORT midiexport_plugin_descriptor = | ||
{ | ||
STRINGIFY( PLUGIN_NAME ), | ||
"MIDI Export", | ||
QT_TRANSLATE_NOOP( "pluginBrowser", | ||
"Filter for exporting MIDI-files from LMMS" ), | ||
"Mohamed Abdel Maksoud <mohamed at amaksoud.com>", | ||
0x0100, | ||
Plugin::ExportFilter, | ||
NULL, | ||
NULL, | ||
NULL | ||
} ; | ||
|
||
} | ||
|
||
|
||
MidiExport::MidiExport() : ExportFilter( &midiexport_plugin_descriptor) | ||
{ | ||
} | ||
|
||
|
||
|
||
|
||
MidiExport::~MidiExport() | ||
{ | ||
} | ||
|
||
|
||
|
||
bool MidiExport::tryExport( const TrackContainer::TrackList &tracks, int tempo, const QString &filename ) | ||
{ | ||
QFile f(filename); | ||
f.open(QIODevice::WriteOnly); | ||
QDataStream midiout(&f); | ||
|
||
InstrumentTrack* instTrack; | ||
QDomElement element; | ||
|
||
|
||
int nTracks = 0; | ||
const int BUFFER_SIZE = 50*1024; | ||
uint8_t buffer[BUFFER_SIZE]; | ||
uint32_t size; | ||
|
||
foreach( Track* track, tracks ) if( track->type() == Track::InstrumentTrack ) nTracks++; | ||
|
||
// midi header | ||
MidiFile::MIDIHeader header(nTracks); | ||
size = header.writeToBuffer(buffer); | ||
midiout.writeRawData((char *)buffer, size); | ||
|
||
// midi tracks | ||
foreach( Track* track, tracks ) | ||
{ | ||
DataFile dataFile( DataFile::SongProject ); | ||
MidiFile::MIDITrack<BUFFER_SIZE> mtrack; | ||
|
||
if( track->type() != Track::InstrumentTrack ) continue; | ||
|
||
//qDebug() << "exporting " << track->name(); | ||
|
||
|
||
mtrack.addName(track->name().toStdString(), 0); | ||
//mtrack.addProgramChange(0, 0); | ||
mtrack.addTempo(tempo, 0); | ||
|
||
instTrack = dynamic_cast<InstrumentTrack *>( track ); | ||
element = instTrack->saveState( dataFile, dataFile.content() ); | ||
|
||
// instrumentTrack | ||
// - instrumentTrack | ||
// - pattern | ||
int base_pitch = 0; | ||
double base_volume = 1.0; | ||
int base_time = 0; | ||
|
||
|
||
for(QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling()) | ||
{ | ||
//QDomText txt = n.toText(); | ||
//qDebug() << ">> child node " << n.nodeName(); | ||
|
||
if (n.nodeName() == "instrumenttrack") | ||
{ | ||
// TODO interpret pan="0" fxch="0" usemasterpitch="1" pitchrange="1" pitch="0" basenote="57" | ||
QDomElement it = n.toElement(); | ||
base_pitch = it.attribute("pitch", "0").toInt(); | ||
base_volume = it.attribute("volume", "100").toDouble()/100.0; | ||
} | ||
|
||
if (n.nodeName() == "pattern") | ||
{ | ||
base_time = n.toElement().attribute("pos", "0").toInt(); | ||
// TODO interpret steps="12" muted="0" type="1" name="Piano1" len="2592" | ||
for(QDomNode nn = n.firstChild(); !nn.isNull(); nn = nn.nextSibling()) | ||
{ | ||
QDomElement note = nn.toElement(); | ||
if (note.attribute("len", "0") == "0" || note.attribute("vol", "0") == "0") continue; | ||
#if 0 | ||
qDebug() << ">>>> key " << note.attribute( "key", "0" ) | ||
<< " " << note.attribute("len", "0") << " @" | ||
<< note.attribute("pos", "0"); | ||
#endif | ||
mtrack.addNote( | ||
note.attribute("key", "0").toInt()+base_pitch | ||
, 100 * base_volume * (note.attribute("vol", "100").toDouble()/100) | ||
, (base_time+note.attribute("pos", "0").toDouble())/48 | ||
, (note.attribute("len", "0")).toDouble()/48); | ||
} | ||
} | ||
|
||
} | ||
size = mtrack.writeToBuffer(buffer); | ||
midiout.writeRawData((char *)buffer, size); | ||
} // for each track | ||
|
||
return true; | ||
|
||
} | ||
|
||
|
||
|
||
|
||
void MidiExport::error() | ||
{ | ||
//qDebug() << "MidiExport error: " << m_error ; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mohamed--abdel-maksoud I guess you wanted to implement something here? |
||
} | ||
|
||
|
||
|
||
extern "C" | ||
{ | ||
|
||
// necessary for getting instance out of shared lib | ||
Plugin * PLUGIN_EXPORT lmms_plugin_main( Model *, void * _data ) | ||
{ | ||
return new MidiExport(); | ||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* MidiExport.h - support for Exporting MIDI-files | ||
* | ||
* Author: Mohamed Abdel Maksoud <mohamed at amaksoud.com> | ||
* | ||
* This file is part of LMMS - http://lmms.io | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program (see COPYING); if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301 USA. | ||
* | ||
*/ | ||
|
||
#ifndef _MIDI_EXPORT_H | ||
#define _MIDI_EXPORT_H | ||
|
||
#include <QString> | ||
|
||
#include "ExportFilter.h" | ||
#include "MidiFile.hpp" | ||
|
||
|
||
|
||
class MidiExport: public ExportFilter | ||
{ | ||
// Q_OBJECT | ||
public: | ||
MidiExport( ); | ||
~MidiExport(); | ||
|
||
virtual PluginView * instantiateView( QWidget * ) | ||
{ | ||
return( NULL ); | ||
} | ||
|
||
virtual bool tryExport( const TrackContainer::TrackList &tracks, int tempo, const QString &filename ); | ||
|
||
private: | ||
|
||
|
||
void error( void ); | ||
|
||
|
||
} ; | ||
|
||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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...