37 : m_nFormat( nFormat )
38 , m_nTracks( nTracks )
83 for (
unsigned i = 0; i <
m_eventList.size(); i++ ) {
93 std::vector<char> trackData;
95 for (
unsigned i = 0; i <
m_eventList.size(); i++ ) {
100 for (
unsigned j = 0; j < buf.size(); j++ ) {
101 trackData.push_back( buf[ j ] );
111 std::vector<char> trackBuf = buf.
getBuffer();
113 for (
unsigned i = 0; i < trackData.size(); i++ ) {
114 trackBuf.push_back( trackData[i] );
119 trackBuf.push_back( 0x00 );
120 trackBuf.push_back( 0xFF );
121 trackBuf.push_back( 0x2F );
122 trackBuf.push_back( 0x00 );
155 for (
unsigned i = 0; i <
m_trackList.size(); i++ ) {
172 std::vector<char> smfVect;
176 for (
unsigned i = 0; i < headerVect.size(); i++ ) {
177 smfVect.push_back( headerVect[ i ] );
182 for (
unsigned nTrack = 0; nTrack <
m_trackList.size(); nTrack++ ) {
184 std::vector<char> trackVect = pTrack->
getBuffer();
185 for (
unsigned i = 0; i < trackVect.size(); i++ ) {
186 smfVect.push_back( trackVect[ i ] );
197constexpr unsigned int TPQN = 192;
229 AutomationPath* pAutomationPath = pSong->getVelocityAutomationPath();
234 auto pInstrumentList = pSong->getInstrumentList();
237 for (
unsigned nPatternList = 0 ;
238 nPatternList < pSong->getPatternGroupVector()->size() ;
242 ( *(pSong->getPatternGroupVector()) )[ nPatternList ];
244 int nStartTicks = nTick;
245 int nMaxPatternLength = 0;
246 for (
unsigned nPattern = 0 ;
247 nPattern < pPatternList->
size() ;
249 Pattern *pPattern = pPatternList->
get( nPattern );
251 if ( (
int )pPattern->
get_length() > nMaxPatternLength ) {
255 for (
unsigned nNote = 0; nNote < pPattern->
get_length(); nNote++ ) {
258 Note *pNote = it->second;
260 float rnd = (float)rand()/(float)RAND_MAX;
265 float fPos = nPatternList + (float)nNote/(
float)nMaxPatternLength;
266 float fVelocityAdjustment = pAutomationPath->
get_value(fPos);
268 (int)( 127.0 * pNote->
get_velocity() * fVelocityAdjustment );
273 int nChannel = pInstr->get_midi_out_channel();
274 if ( nChannel == -1 ) {
279 if ( nLength == -1 ) {
285 eventList->push_back(
294 eventList->push_back(
296 nStartTicks + nNote + nLength,
306 nTick += nMaxPatternLength;
320 for (
unsigned i = 0; i < pEvents->size(); i++ ) {
321 for ( std::vector<SMFEvent*>::iterator it = pEvents->begin() ;
322 it != ( pEvents->end() - 1 ) ;
339 FILE* pFile = fopen( sFilename.toLocal8Bit(),
"wb" );
341 if( pFile ==
nullptr ) {
345 std::vector<char> smfVect = pSmf->
getBuffer();
346 for (
unsigned i = 0; i < smfVect.size(); i++ ) {
347 fwrite( &smfVect[ i ], 1, 1, pFile );
417 unsigned nLastTick = 1;
419 pEvent->m_nDeltaTime = ( pEvent->m_nTicks - nLastTick ) * 4;
420 nLastTick = pEvent->m_nTicks;
449 auto pInstrumentList = pSong->getInstrumentList();
451 for(
unsigned nInstr=0; nInstr < pInstrumentList->size(); nInstr++ ){
459 int nInstr = pSong->getInstrumentList()->index(pInstr);
468 auto pInstrumentList = pSong->getInstrumentList();
469 for (
unsigned nTrack = 0; nTrack <
m_eventLists.size(); nTrack++ ) {
471 auto instrument = pInstrumentList->get( nTrack );
481 unsigned nLastTick = 1;
482 for ( std::vector<SMFEvent*>::iterator it = pEventList->begin();
483 it != pEventList->end();
539 unsigned nLastTick = 1;
540 for ( std::vector<SMFEvent*>::iterator it =
m_eventList.begin();
#define FOREACH_NOTE_CST_IT_BOUND_LENGTH(_notes, _it, _bound, _pattern)
Iterate over all notes in column _bound in an immutable way if it is contained in _pattern.
float get_value(float x) const noexcept
Get value at given location.
A note plays an associated instrument with a velocity left and right pan.
std::shared_ptr< Instrument > get_instrument()
__instrument accessor
int get_length() const
__length accessor
int get_midi_key() const
return scaled key for midi output, !!! DO NOT CHECK IF INSTRUMENT IS SET !!!
float get_velocity() const
__velocity accessor
float get_probability() const
PatternList is a collection of patterns.
int size() const
returns the numbers of patterns
Pattern * get(int idx)
get a pattern from the list
Pattern class is a Note container.
int get_length() const
set the denominator of the pattern
const notes_t * get_notes() const
get the virtual pattern set
std::multimap< int, Note * > notes_t
< multimap note type
virtual void prepareEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
virtual EventList * getEvents(std::shared_ptr< Song > pSong, std::shared_ptr< Instrument > pInstr) override
virtual SMF * createSMF(std::shared_ptr< Song > pSong) override
virtual void packEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
virtual void prepareEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
virtual EventList * getEvents(std::shared_ptr< Song > pSong, std::shared_ptr< Instrument > pInstr) override
std::vector< EventList * > m_eventLists
virtual ~SMF1WriterMulti()
virtual void packEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
virtual void prepareEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
virtual EventList * getEvents(std::shared_ptr< Song > pSong, std::shared_ptr< Instrument > pInstr) override
virtual ~SMF1WriterSingle()
virtual void packEvents(std::shared_ptr< Song > pSong, SMF *pSmf) override
virtual SMF * createSMF(std::shared_ptr< Song > pSong) override
virtual std::vector< char > getBuffer()=0
std::vector< char > getBuffer()
std::vector< char > m_buffer
void writeDWord(long nVal)
virtual std::vector< char > getBuffer() override
std::vector< SMFEvent * > m_eventList
void addEvent(SMFEvent *pEvent)
void saveSMF(const QString &sFilename, SMF *pSmf)
virtual void packEvents(std::shared_ptr< Song > pSong, SMF *pSmf)=0
virtual SMF * createSMF(std::shared_ptr< Song > pSong)=0
void sortEvents(EventList *pEventList)
virtual EventList * getEvents(std::shared_ptr< Song > pSong, std::shared_ptr< Instrument > pInstr)=0
SMFTrack * createTrack0(std::shared_ptr< Song > pSong)
virtual void prepareEvents(std::shared_ptr< Song > pSong, SMF *pSmf)=0
void save(const QString &sFilename, std::shared_ptr< Song > pSong)
void addTrack(SMFTrack *pTrack)
std::vector< SMFTrack * > m_trackList
virtual std::vector< char > getBuffer() override
SMF(int nFormat, int nTPQN)
constexpr unsigned int DRUM_CHANNEL
constexpr unsigned int NOTE_LENGTH
constexpr unsigned int TPQN
std::vector< SMFEvent * > EventList