MidiExport.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * MidiExport.h - support for Exporting MIDI-files
  3. *
  4. * Copyright (c) 2015 Mohamed Abdel Maksoud <mohamed at amaksoud.com>
  5. * Copyright (c) 2017 Hyunjin Song <tteu.ingog/at/gmail.com>
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #ifndef _MIDI_EXPORT_H
  26. #define _MIDI_EXPORT_H
  27. #include <QString>
  28. #include "ExportFilter.h"
  29. #include "MidiFile.hpp"
  30. const int BUFFER_SIZE = 50*1024;
  31. typedef MidiFile::MIDITrack<BUFFER_SIZE> MTrack;
  32. struct MidiNote
  33. {
  34. int time;
  35. uint8_t pitch;
  36. int duration;
  37. uint8_t volume;
  38. inline bool operator<(const MidiNote &b) const
  39. {
  40. return this->time < b.time;
  41. }
  42. } ;
  43. typedef std::vector<MidiNote> MidiNoteVector;
  44. typedef std::vector<MidiNote>::iterator MidiNoteIterator;
  45. class MidiExport: public ExportFilter
  46. {
  47. // Q_OBJECT
  48. public:
  49. MidiExport();
  50. ~MidiExport();
  51. virtual PluginView *instantiateView(QWidget *)
  52. {
  53. return nullptr;
  54. }
  55. virtual bool tryExport(const TrackContainer::TrackList &tracks,
  56. const TrackContainer::TrackList &tracks_BB,
  57. int tempo, int masterPitch, const QString &filename);
  58. private:
  59. void writePattern(MidiNoteVector &pat, QDomNode n,
  60. int base_pitch, double base_volume, int base_time);
  61. void writePatternToTrack(MTrack &mtrack, MidiNoteVector &nv);
  62. void writeBBPattern(MidiNoteVector &src, MidiNoteVector &dst,
  63. int len, int base, int start, int end);
  64. void ProcessBBNotes(MidiNoteVector &nv, int cutPos);
  65. void error();
  66. } ;
  67. #endif