hydrogen 1.2.6
SMF.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2025 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (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
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#ifndef SMF_H
24#define SMF_H
25
26#include <core/Object.h>
27
28#include <string>
29#include <cstdio>
30#include <QByteArray>
31
32#include <core/SMF/SMFEvent.h>
33
34namespace H2Core
35{
36
37class Song;
38class Instrument;
39
41class SMFHeader : public Object<SMFHeader>, public SMFBase
42{
44public:
45 SMFHeader( int nFormat, int nTracks, int nTPQN );
46 ~SMFHeader();
47
48 void addTrack();
49 virtual QByteArray getBuffer() const override;
50 virtual QString toQString() const override;
51
52private:
55 int m_nTPQN;
56};
57
58
59
61class SMFTrack : public Object<SMFTrack>, public SMFBase
62{
64public:
65
66 SMFTrack();
67 ~SMFTrack();
68
69 void addEvent( SMFEvent *pEvent );
70
71 virtual QByteArray getBuffer() const override;
72 virtual QString toQString() const override;
73
74private:
75 std::vector<SMFEvent*> m_eventList;
76};
77
78
79
81class SMF : public Object<SMF>, public SMFBase
82{
84public:
85 SMF( int nFormat, int nTPQN );
86 ~SMF();
87
88 void addTrack( SMFTrack *pTrack );
89 virtual QByteArray getBuffer() const override;
90 virtual QString toQString() const override;
91
92private:
93 std::vector<SMFTrack*> m_trackList;
94
96};
97
98
99
100typedef std::vector<SMFEvent*> EventList;
101
102
104class SMFWriter : public H2Core::Object<SMFWriter>
105{
107public:
108 SMFWriter();
109 virtual ~SMFWriter();
110 void save( const QString& sFilename, std::shared_ptr<Song> pSong );
111
112protected:
113 void sortEvents( EventList* pEventList );
114 SMFTrack* createTrack0( std::shared_ptr<Song> pSong );
115
116 virtual SMF* createSMF( std::shared_ptr<Song> pSong ) = 0;
117 virtual void prepareEvents( std::shared_ptr<Song> pSong, SMF* pSmf )=0;
118 virtual EventList* getEvents( std::shared_ptr<Song> pSong, std::shared_ptr<Instrument> pInstr ) = 0;
119 virtual void packEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) = 0;
120
121private:
122 void saveSMF( const QString& sFilename, SMF* pSmf );
123};
124
125
126//-------
127
129class SMF1Writer : public Object<SMF1Writer>, public SMFWriter
130{
132public:
133 SMF1Writer();
134 virtual ~SMF1Writer();
135protected:
136 virtual SMF* createSMF( std::shared_ptr<Song> pSong ) override;
137};
138
139
141class SMF1WriterSingle : public Object<SMF1WriterSingle>, public SMF1Writer
142{
144public:
146 virtual ~SMF1WriterSingle();
147protected:
148 virtual void prepareEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) override;
149 virtual void packEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) override;
150 virtual EventList* getEvents( std::shared_ptr<Song> pSong, std::shared_ptr<Instrument> pInstr ) override;
151private:
153};
154
155
157class SMF1WriterMulti : public Object<SMF1WriterMulti>, public SMF1Writer
158{
160public:
162 virtual ~SMF1WriterMulti();
163protected:
164 virtual void prepareEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) override;
165 virtual void packEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) override;
166 virtual EventList* getEvents( std::shared_ptr<Song> pSong, std::shared_ptr<Instrument> pInstr ) override;
167private:
168 // contains events for each instrument in separate vector
169 std::vector<EventList*> m_eventLists;
170};
171
172
173//-------
174
176class SMF0Writer : public Object<SMF0Writer>, public SMFWriter
177{
179public:
180 SMF0Writer();
181 virtual ~SMF0Writer();
182protected:
183 virtual SMF* createSMF( std::shared_ptr<Song> pSong ) override;
184 virtual void prepareEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) override;
185 virtual void packEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) override;
186 virtual EventList* getEvents( std::shared_ptr<Song> pSong, std::shared_ptr<Instrument> pInstr ) override;
187private:
190};
191
192
193
194};
195
196#endif
197
#define H2_OBJECT(name)
Definition Object.h:227
Instrument class.
Definition Instrument.h:55
virtual void prepareEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
Definition SMF.cpp:531
SMFTrack * m_pTrack
Definition SMF.h:188
virtual EventList * getEvents(std::shared_ptr< Song > pSong, std::shared_ptr< Instrument > pInstr) override
Definition SMF.cpp:525
EventList m_eventList
Definition SMF.h:189
virtual ~SMF0Writer()
Definition SMF.cpp:511
virtual SMF * createSMF(std::shared_ptr< Song > pSong) override
Definition SMF.cpp:516
virtual void packEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
Definition SMF.cpp:537
virtual void prepareEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
Definition SMF.cpp:449
virtual EventList * getEvents(std::shared_ptr< Song > pSong, std::shared_ptr< Instrument > pInstr) override
Definition SMF.cpp:459
std::vector< EventList * > m_eventLists
Definition SMF.h:169
virtual ~SMF1WriterMulti()
Definition SMF.cpp:444
virtual void packEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
Definition SMF.cpp:468
virtual void prepareEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
Definition SMF.cpp:405
virtual EventList * getEvents(std::shared_ptr< Song > pSong, std::shared_ptr< Instrument > pInstr) override
Definition SMF.cpp:398
EventList m_eventList
Definition SMF.h:152
virtual ~SMF1WriterSingle()
Definition SMF.cpp:392
virtual void packEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
Definition SMF.cpp:412
virtual SMF * createSMF(std::shared_ptr< Song > pSong) override
Definition SMF.cpp:368
virtual ~SMF1Writer()
Definition SMF.cpp:363
int m_nTPQN
ticks per quarter note
Definition SMF.h:55
SMFHeader(int nFormat, int nTracks, int nTPQN)
Definition SMF.cpp:38
int m_nTracks
number of tracks
Definition SMF.h:54
virtual QByteArray getBuffer() const override
Definition SMF.cpp:56
void addTrack()
Definition SMF.cpp:52
virtual QString toQString() const override
Definition SMF.cpp:69
int m_nFormat
SMF format.
Definition SMF.h:53
virtual QByteArray getBuffer() const override
Definition SMF.cpp:96
virtual QString toQString() const override
Definition SMF.cpp:133
std::vector< SMFEvent * > m_eventList
Definition SMF.h:75
void addEvent(SMFEvent *pEvent)
Definition SMF.cpp:137
void saveSMF(const QString &sFilename, SMF *pSmf)
Definition SMF.cpp:337
virtual void packEvents(std::shared_ptr< Song > pSong, SMF *pSmf)=0
virtual SMF * createSMF(std::shared_ptr< Song > pSong)=0
void sortEvents(EventList *pEventList)
Definition SMF.cpp:318
virtual EventList * getEvents(std::shared_ptr< Song > pSong, std::shared_ptr< Instrument > pInstr)=0
virtual ~SMFWriter()
Definition SMF.cpp:208
SMFTrack * createTrack0(std::shared_ptr< Song > pSong)
Definition SMF.cpp:214
virtual void prepareEvents(std::shared_ptr< Song > pSong, SMF *pSmf)=0
void save(const QString &sFilename, std::shared_ptr< Song > pSong)
Definition SMF.cpp:224
void addTrack(SMFTrack *pTrack)
Definition SMF.cpp:168
SMFHeader * m_pHeader
Definition SMF.h:95
virtual QByteArray getBuffer() const override
Definition SMF.cpp:176
std::vector< SMFTrack * > m_trackList
Definition SMF.h:93
virtual QString toQString() const override
Definition SMF.cpp:190
SMF(int nFormat, int nTPQN)
Definition SMF.cpp:146
Song class.
Definition Song.h:61
std::vector< SMFEvent * > EventList
Definition SMF.h:100