LMMS
Loading...
Searching...
No Matches
MidiExport.h
Go to the documentation of this file.
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
26#ifndef _MIDI_EXPORT_H
27#define _MIDI_EXPORT_H
28
29
30#include "ExportFilter.h"
31#include "MidiFile.hpp"
32#include "Note.h"
33
34class QDomNode;
35
36namespace lmms
37{
38
39
40const int BUFFER_SIZE = 50*1024;
41using MTrack = MidiFile::MIDITrack<BUFFER_SIZE>;
42
44{
45 int time;
50
51 inline bool operator<(const MidiNote &b) const
52 {
53 return this->time < b.time;
54 }
55} ;
56
57using MidiNoteVector = std::vector<MidiNote>;
58using MidiNoteIterator = std::vector<MidiNote>::iterator;
59
61{
62// Q_OBJECT
63public:
64 MidiExport();
65 ~MidiExport() override = default;
66
67 // Default Beat Length in ticks for step notes
68 // TODO: The beat length actually varies per note, however the method that
69 // calculates it (InstrumentTrack::beatLen) requires a NotePlayHandle to do
70 // so. While we don't figure out a way to hold the beat length of each note
71 // on its member variables, we will use a default value as a beat length that
72 // will be used as an upper limit of the midi note length. This doesn't worsen
73 // the current logic used for MidiExport because right now the beat length is
74 // not even considered during the generation of the MIDI.
75 static constexpr int DefaultBeatLength = 1500;
76
77 gui::PluginView* instantiateView(QWidget *) override
78 {
79 return nullptr;
80 }
81
82 bool tryExport(const TrackContainer::TrackList &tracks,
83 const TrackContainer::TrackList &patternTracks,
84 int tempo, int masterPitch, const QString &filename) override;
85
86private:
87 void writeMidiClip(MidiNoteVector &midiClip, const QDomNode& n,
88 int base_pitch, double base_volume, int base_time);
91 int len, int base, int start, int end);
92 void processPatternNotes(MidiNoteVector &nv, int cutPos);
93
94 void error();
95
96
97} ;
98
99
100} // namespace lmms
101
102#endif
ExportFilter(const Descriptor *_descriptor)
Definition ExportFilter.h:42
~MidiExport() override=default
void processPatternNotes(MidiNoteVector &nv, int cutPos)
Definition MidiExport.cpp:320
MidiExport()
Definition MidiExport.cpp:63
bool tryExport(const TrackContainer::TrackList &tracks, const TrackContainer::TrackList &patternTracks, int tempo, int masterPitch, const QString &filename) override
Definition MidiExport.cpp:70
void writeMidiClip(MidiNoteVector &midiClip, const QDomNode &n, int base_pitch, double base_volume, int base_time)
Definition MidiExport.cpp:264
static constexpr int DefaultBeatLength
Definition MidiExport.h:75
void error()
Definition MidiExport.cpp:340
gui::PluginView * instantiateView(QWidget *) override
Create a view for the model.
Definition MidiExport.h:77
void writeMidiClipToTrack(MTrack &mtrack, MidiNoteVector &nv)
Definition MidiExport.cpp:286
void writePatternClip(MidiNoteVector &src, MidiNoteVector &dst, int len, int base, int start, int end)
Definition MidiExport.cpp:296
Type
Definition Note.h:119
std::vector< Track * > TrackList
Definition TrackContainer.h:52
Definition PluginView.h:36
virtual ASIOError start()=0
unsigned char uint8_t
Definition mid.cpp:98
Definition AudioAlsa.cpp:35
MidiFile::MIDITrack< BUFFER_SIZE > MTrack
Definition MidiExport.h:41
const int BUFFER_SIZE
Definition MidiExport.h:40
std::vector< MidiNote > MidiNoteVector
Definition MidiExport.h:57
std::vector< MidiNote >::iterator MidiNoteIterator
Definition MidiExport.h:58
QString filename
Definition HydrogenImport.cpp:42
Definition MidiExport.h:44
int duration
Definition MidiExport.h:47
Note::Type type
Definition MidiExport.h:49
bool operator<(const MidiNote &b) const
Definition MidiExport.h:51
int time
Definition MidiExport.h:45
uint8_t pitch
Definition MidiExport.h:46
uint8_t volume
Definition MidiExport.h:48
int n
Definition crypt.c:458
b
Definition crypt.c:628