summaryrefslogtreecommitdiffabout
path: root/include/midillo/MThd.h
blob: 20263cdc478feb4622f81441103f05e0aad4d8b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef __MIDILLO_MTHD_H
#define __MIDILLO_MTHD_H

#include <istream>
#include <ostream>
#include <midillo/chunk.h>

/**
 * @file
 * @brief the MThd_t -- MThd header chunk class
 */

namespace midillo {
    using std::istream;
    using std::ostream;

    /**
     * MThd header chunk container
     */
    class MThd_t : public chunk_t {
	public:
	    enum {
		fmt_0 = 0, fmt_1 = 1, fmt_2 = 2,
		fmt_singletrack = fmt_0,
		fmt_multitrack = fmt_1,
		fmt_tracksequence = fmt_2
	    };
	    /**
	     * SMF format. 0 for single track, 1 for multitrack, 2 for track
	     * sequence.
	     */
	    int fmt;
	    /**
	     * Number of tracks in the file
	     */
	    int ntracks;
	    /**
	     * The number of pulses per quarter note
	     */
	    int division;

	    /**
	     * Load MThd chunk from the stream
	     * @param s input stream
	     */
	    void load(istream& s);

	    /**
	     * Read MThd chunk data from the stream. This function assumes that
	     * header is already read.
	     * @param s input stream
	     */
	    void load_data(istream& s);

	    /**
	     * Save MThd chunk to the stream
	     * @param s output stream
	     */
	    void save(ostream& s) const;

	    /**
	     * Dump textual representation of MThd chunk to stream
	     * @param s output stream
	     */
	    void dump(ostream& s) const;
    };

    inline ostream& operator<<(ostream& s,const MThd_t& mthd) {
	mthd.dump(s); return s;
    }

}

#endif /* MIDILLO_MTHD_H */