Made 0.4.12 release
[lmms/mlankhorst.git] / plugins / midi_import / MidiImport.h
bloba6dd4dce266d530e093323119c5d12f602752be7
1 /*
2 * MidiImport.h - support for importing MIDI-files
4 * Copyright (c) 2005-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
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.
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.
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.
25 #ifndef _MIDI_IMPORT_H
26 #define _MIDI_IMPORT_H
28 #include <QtCore/QString>
29 #include <QtCore/QPair>
30 #include <QtCore/QVector>
32 #include "midi.h"
33 #include "ImportFilter.h"
36 class MidiImport : public ImportFilter
38 public:
39 MidiImport( const QString & _file );
40 virtual ~MidiImport();
42 virtual PluginView * instantiateView( QWidget * )
44 return( NULL );
48 private:
49 virtual bool tryImport( trackContainer * _tc );
51 bool readSMF( trackContainer * _tc );
52 bool readRIFF( trackContainer * _tc );
53 bool readTrack( int _track_end, QString & _track_name );
55 void error( void );
58 inline int readInt( int _bytes )
60 int c, value = 0;
63 c = readByte();
64 if( c == -1 )
66 return( -1 );
68 value = ( value << 8 ) | c;
69 } while( --_bytes );
70 return( value );
72 inline Sint32 read32LE( void )
74 int value = readByte();
75 value |= readByte() << 8;
76 value |= readByte() << 16;
77 value |= readByte() << 24;
78 return( value );
80 inline int readVar( void )
82 int c = readByte();
83 int value = c & 0x7f;
84 if( c & 0x80 )
86 c = readByte();
87 value = ( value << 7 ) | ( c & 0x7f );
88 if( c & 0x80 )
90 c = readByte();
91 value = ( value << 7 ) | ( c & 0x7f );
92 if( c & 0x80 )
94 c = readByte();
95 value = ( value << 7 ) | c;
96 if( c & 0x80 )
98 return -1;
103 return( !file().atEnd() ? value : -1 );
106 inline Sint32 readID( void )
108 return( read32LE() );
110 inline void skip( int _bytes )
112 while( _bytes > 0 )
114 readByte();
115 --_bytes;
120 typedef QVector<QPair<int, midiEvent> > eventVector;
121 eventVector m_events;
122 int m_timingDivision;
127 #endif