hydrogen 1.2.3
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-2024 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 <vector>
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 std::vector<char> getBuffer() override;
50
51private:
54 int m_nTPQN;
55};
56
57
58
60class SMFTrack : public Object<SMFTrack>, public SMFBase
61{
63public:
64
65 SMFTrack();
66 ~SMFTrack();
67
68 void addEvent( SMFEvent *pEvent );
69
70 virtual std::vector<char> getBuffer() override;
71
72private:
73 std::vector<SMFEvent*> m_eventList;
74};
75
76
77
79class SMF : public Object<SMF>, public SMFBase
80{
82public:
83 SMF( int nFormat, int nTPQN );
84 ~SMF();
85
86 void addTrack( SMFTrack *pTrack );
87 virtual std::vector<char> getBuffer() override;
88
89private:
90 std::vector<SMFTrack*> m_trackList;
91
93};
94
95
96
97typedef std::vector<SMFEvent*> EventList;
98
99
101class SMFWriter : public H2Core::Object<SMFWriter>
102{
104public:
105 SMFWriter();
106 virtual ~SMFWriter();
107 void save( const QString& sFilename, std::shared_ptr<Song> pSong );
108
109protected:
110 void sortEvents( EventList* pEventList );
111 SMFTrack* createTrack0( std::shared_ptr<Song> pSong );
112
113 virtual SMF* createSMF( std::shared_ptr<Song> pSong ) = 0;
114 virtual void prepareEvents( std::shared_ptr<Song> pSong, SMF* pSmf )=0;
115 virtual EventList* getEvents( std::shared_ptr<Song> pSong, std::shared_ptr<Instrument> pInstr ) = 0;
116 virtual void packEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) = 0;
117
118private:
119 void saveSMF( const QString& sFilename, SMF* pSmf );
120};
121
122
123//-------
124
126class SMF1Writer : public Object<SMF1Writer>, public SMFWriter
127{
129public:
130 SMF1Writer();
131 virtual ~SMF1Writer();
132protected:
133 virtual SMF* createSMF( std::shared_ptr<Song> pSong ) override;
134};
135
136
138class SMF1WriterSingle : public Object<SMF1WriterSingle>, public SMF1Writer
139{
141public:
143 virtual ~SMF1WriterSingle();
144protected:
145 virtual void prepareEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) override;
146 virtual void packEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) override;
147 virtual EventList* getEvents( std::shared_ptr<Song> pSong, std::shared_ptr<Instrument> pInstr ) override;
148private:
150};
151
152
154class SMF1WriterMulti : public Object<SMF1WriterMulti>, public SMF1Writer
155{
157public:
159 virtual ~SMF1WriterMulti();
160protected:
161 virtual void prepareEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) override;
162 virtual void packEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) override;
163 virtual EventList* getEvents( std::shared_ptr<Song> pSong, std::shared_ptr<Instrument> pInstr ) override;
164private:
165 // contains events for each instrument in separate vector
166 std::vector<EventList*> m_eventLists;
167};
168
169
170//-------
171
173class SMF0Writer : public Object<SMF0Writer>, public SMFWriter
174{
176public:
177 SMF0Writer();
178 virtual ~SMF0Writer();
179protected:
180 virtual SMF* createSMF( std::shared_ptr<Song> pSong ) override;
181 virtual void prepareEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) override;
182 virtual void packEvents( std::shared_ptr<Song> pSong, SMF* pSmf ) override;
183 virtual EventList* getEvents( std::shared_ptr<Song> pSong, std::shared_ptr<Instrument> pInstr ) override;
184private:
187};
188
189
190
191};
192
193#endif
194
#define H2_OBJECT(name)
Definition Object.h:224
virtual void prepareEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
Definition Smf.cpp:529
SMFTrack * m_pTrack
Definition SMF.h:185
virtual EventList * getEvents(std::shared_ptr< Song > pSong, std::shared_ptr< Instrument > pInstr) override
Definition Smf.cpp:523
EventList m_eventList
Definition SMF.h:186
virtual ~SMF0Writer()
Definition Smf.cpp:509
virtual SMF * createSMF(std::shared_ptr< Song > pSong) override
Definition Smf.cpp:514
virtual void packEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
Definition Smf.cpp:535
virtual void prepareEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
Definition Smf.cpp:447
virtual EventList * getEvents(std::shared_ptr< Song > pSong, std::shared_ptr< Instrument > pInstr) override
Definition Smf.cpp:457
std::vector< EventList * > m_eventLists
Definition SMF.h:166
virtual ~SMF1WriterMulti()
Definition Smf.cpp:442
virtual void packEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
Definition Smf.cpp:466
virtual void prepareEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
Definition Smf.cpp:403
virtual EventList * getEvents(std::shared_ptr< Song > pSong, std::shared_ptr< Instrument > pInstr) override
Definition Smf.cpp:396
EventList m_eventList
Definition SMF.h:149
virtual ~SMF1WriterSingle()
Definition Smf.cpp:390
virtual void packEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
Definition Smf.cpp:410
virtual SMF * createSMF(std::shared_ptr< Song > pSong) override
Definition Smf.cpp:366
virtual ~SMF1Writer()
Definition Smf.cpp:361
int m_nTPQN
ticks per quarter note
Definition SMF.h:54
SMFHeader(int nFormat, int nTracks, int nTPQN)
Definition Smf.cpp:36
int m_nTracks
number of tracks
Definition SMF.h:53
void addTrack()
Definition Smf.cpp:50
virtual std::vector< char > getBuffer() override
Definition Smf.cpp:54
int m_nFormat
SMF format.
Definition SMF.h:52
virtual std::vector< char > getBuffer() override
Definition Smf.cpp:90
std::vector< SMFEvent * > m_eventList
Definition SMF.h:73
void addEvent(SMFEvent *pEvent)
Definition Smf.cpp:131
void saveSMF(const QString &sFilename, SMF *pSmf)
Definition Smf.cpp:336
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:317
virtual EventList * getEvents(std::shared_ptr< Song > pSong, std::shared_ptr< Instrument > pInstr)=0
virtual ~SMFWriter()
Definition Smf.cpp:207
SMFTrack * createTrack0(std::shared_ptr< Song > pSong)
Definition Smf.cpp:213
virtual void prepareEvents(std::shared_ptr< Song > pSong, SMF *pSmf)=0
void save(const QString &sFilename, std::shared_ptr< Song > pSong)
Definition Smf.cpp:223
void addTrack(SMFTrack *pTrack)
Definition Smf.cpp:162
SMFHeader * m_pHeader
Definition SMF.h:92
std::vector< SMFTrack * > m_trackList
Definition SMF.h:90
virtual std::vector< char > getBuffer() override
Definition Smf.cpp:170
SMF(int nFormat, int nTPQN)
Definition Smf.cpp:140
std::vector< SMFEvent * > EventList
Definition SMF.h:97