70 return QString(
getBuffer().toHex(
' ' ) );
89 for (
unsigned i = 0; i <
m_eventList.size(); i++ ) {
100 for (
unsigned i = 0; i <
m_eventList.size(); i++ ) {
104 for (
unsigned j = 0; j < buf.size(); j++ ) {
105 trackData.push_back( buf[ j ] );
117 for (
unsigned i = 0; i < trackData.size(); i++ ) {
118 trackBuf.push_back( trackData[i] );
123 trackBuf.push_back(
static_cast<char>(0x00) );
124 trackBuf.push_back(
static_cast<char>(0xFF) );
125 trackBuf.push_back(
static_cast<char>(0x2F) );
126 trackBuf.push_back(
static_cast<char>(0x00) );
134 return QString(
getBuffer().toHex(
' ' ) );
161 for (
unsigned i = 0; i <
m_trackList.size(); i++ ) {
182 for (
unsigned nTrack = 0; nTrack <
m_trackList.size(); nTrack++ ) {
191 return QString(
getBuffer().toHex(
' ' ) );
198constexpr unsigned int TPQN = 192;
226 INFOLOG( QString(
"Export MIDI to [%1]" ).arg( sFilename ) );
230 AutomationPath* pAutomationPath = pSong->getVelocityAutomationPath();
235 auto pInstrumentList = pSong->getInstrumentList();
238 for (
unsigned nPatternList = 0 ;
239 nPatternList < pSong->getPatternGroupVector()->size() ;
243 ( *(pSong->getPatternGroupVector()) )[ nPatternList ];
245 int nStartTicks = nTick;
246 int nMaxPatternLength = 0;
247 for (
unsigned nPattern = 0 ;
248 nPattern < pPatternList->
size() ;
250 Pattern *pPattern = pPatternList->
get( nPattern );
252 if ( (
int )pPattern->
get_length() > nMaxPatternLength ) {
256 for (
unsigned nNote = 0; nNote < pPattern->
get_length(); nNote++ ) {
259 Note *pNote = it->second;
261 float rnd = (float)rand()/(float)RAND_MAX;
266 float fPos = nPatternList + (float)nNote/(
float)nMaxPatternLength;
267 float fVelocityAdjustment = pAutomationPath->
get_value(fPos);
269 (int)( 127.0 * pNote->
get_velocity() * fVelocityAdjustment );
274 int nChannel = pInstr->get_midi_out_channel();
275 if ( nChannel == -1 ) {
280 if ( nLength == -1 ) {
286 eventList->push_back(
295 eventList->push_back(
297 nStartTicks + nNote + nLength,
307 nTick += nMaxPatternLength;
321 for (
unsigned i = 0; i < pEvents->size(); i++ ) {
322 for ( std::vector<SMFEvent*>::iterator it = pEvents->begin() ;
323 it != ( pEvents->end() - 1 ) ;
340 QFile file( sFilename );
341 if ( ! file.open( QIODevice::WriteOnly ) ) {
342 ERRORLOG( QString(
"Unable to open file [%1] for writing" )
347 QDataStream stream( &file );
349 stream.writeRawData( buffer.constData(), buffer.size() );
419 unsigned nLastTick = 1;
421 pEvent->m_nDeltaTime = ( pEvent->m_nTicks - nLastTick ) * 4;
422 nLastTick = pEvent->m_nTicks;
451 auto pInstrumentList = pSong->getInstrumentList();
453 for(
unsigned nInstr=0; nInstr < pInstrumentList->size(); nInstr++ ){
461 int nInstr = pSong->getInstrumentList()->index(pInstr);
470 auto pInstrumentList = pSong->getInstrumentList();
471 for (
unsigned nTrack = 0; nTrack <
m_eventLists.size(); nTrack++ ) {
473 auto instrument = pInstrumentList->get( nTrack );
483 unsigned nLastTick = 1;
484 for ( std::vector<SMFEvent*>::iterator it = pEventList->begin();
485 it != pEventList->end();
541 unsigned nLastTick = 1;
542 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, !
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 QByteArray getBuffer() const =0
void writeDWord(long nVal)
virtual QByteArray getBuffer() const override
virtual QString toQString() const 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)
virtual QByteArray getBuffer() const override
std::vector< SMFTrack * > m_trackList
virtual QString toQString() const override
SMF(int nFormat, int nTPQN)
constexpr unsigned int DRUM_CHANNEL
constexpr unsigned int NOTE_LENGTH
constexpr unsigned int TPQN
std::vector< SMFEvent * > EventList