LMMS
Loading...
Searching...
No Matches
MidiImport.h
Go to the documentation of this file.
1/*
2 * MidiImport.h - support for importing MIDI-files
3 *
4 * Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef _MIDI_IMPORT_H
26#define _MIDI_IMPORT_H
27
28#include <cstdint>
29#include <QString>
30
31#include "MidiEvent.h"
32#include "ImportFilter.h"
33
34namespace lmms
35{
36
37
39{
40 Q_OBJECT
41public:
42 MidiImport(const QString& file);
43 ~MidiImport() override = default;
44 gui::PluginView* instantiateView(QWidget*) override { return nullptr; }
45
46private:
47 bool tryImport(TrackContainer* tc) override;
48 bool readSMF(TrackContainer* tc);
49 bool readRIFF(TrackContainer* tc);
50 bool readTrack(int track_end, QString& track_name);
51 void error();
52
53 inline std::int32_t read32LE()
54 {
55 std::int32_t value = readByte();
56 value |= readByte() << 8;
57 value |= readByte() << 16;
58 value |= readByte() << 24;
59 return value;
60 }
61
62 inline std::int32_t readVar()
63 {
64 std::int32_t c = readByte();
65 std::int32_t value = c & 0x7f;
66 if (c & 0x80)
67 {
68 c = readByte();
69 value = (value << 7) | (c & 0x7f);
70 if (c & 0x80)
71 {
72 c = readByte();
73 value = (value << 7) | (c & 0x7f);
74 if (c & 0x80)
75 {
76 c = readByte();
77 value = (value << 7) | c;
78 if (c & 0x80) { return -1; }
79 }
80 }
81 }
82 return !file().atEnd() ? value : -1;
83 }
84
85 inline void skip(unsigned num_bytes) { while (num_bytes--) { readByte(); } }
86
88};
89
90
91} // namespace lmms
92
93#endif
ImportFilter(const QString &_file_name, const Descriptor *_descriptor)
Definition ImportFilter.cpp:41
int readByte()
Definition ImportFilter.h:69
const QFile & file() const
Definition ImportFilter.h:57
~MidiImport() override=default
std::int32_t readVar()
Definition MidiImport.h:62
void error()
Definition MidiImport.cpp:584
gui::PluginView * instantiateView(QWidget *) override
Create a view for the model.
Definition MidiImport.h:44
MidiImport(const QString &file)
Definition MidiImport.cpp:85
void skip(unsigned num_bytes)
Definition MidiImport.h:85
bool tryImport(TrackContainer *tc) override
Definition MidiImport.cpp:90
bool readRIFF(TrackContainer *tc)
Definition MidiImport.cpp:549
bool readSMF(TrackContainer *tc)
Definition MidiImport.cpp:264
std::int32_t read32LE()
Definition MidiImport.h:53
int m_timingDivision
Definition MidiImport.h:87
bool readTrack(int track_end, QString &track_name)
Definition TrackContainer.h:49
Definition PluginView.h:36
static PuglViewHint int value
Definition pugl.h:1708
Definition AudioAlsa.cpp:35
return c
Definition crypt.c:175