summaryrefslogtreecommitdiffabout
path: root/include/midillo/chunk.h
authorMichael Krelin <hacker@klever.net>2006-08-11 16:01:56 (UTC)
committer Michael Krelin <hacker@klever.net>2006-08-11 16:01:56 (UTC)
commit0c21a7a0d5b84dc6726462f0fbe51b8c32433262 (patch) (unidiff)
tree9df6334cb1a61efebe68f7bcef9aa119a823626a /include/midillo/chunk.h
parent9bcc235e575a95989a5903394c127accbeef2e0f (diff)
downloadmidillo-0.0.zip
midillo-0.0.tar.gz
midillo-0.0.tar.bz2
initial commit into repository0.0
Diffstat (limited to 'include/midillo/chunk.h') (more/less context) (ignore whitespace changes)
-rw-r--r--include/midillo/chunk.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/include/midillo/chunk.h b/include/midillo/chunk.h
new file mode 100644
index 0000000..8b6c034
--- a/dev/null
+++ b/include/midillo/chunk.h
@@ -0,0 +1,88 @@
1#ifndef __MIDILLO_CHUNK_H
2#define __MIDILLO_CHUNK_H
3
4#include <istream>
5#include <ostream>
6
7/**
8 * @file
9 * @brief Generic SMF chunk manipulation
10 */
11
12namespace midillo {
13 using std::istream;
14 using std::ostream;
15
16 enum {
17 chunk_id_MThd = 0x6468544d,
18 chunk_id_MTrk = 0x6b72544d
19 };
20 /**
21 * Chunk header data structure
22 */
23 struct chunk_header_t {
24 /**
25 * Track signature data
26 */
27 union {
28 /**
29 * ASCII representation
30 */
31 char id_chars[4];
32 /**
33 * long integer representation
34 */
35 unsigned long id_number;
36 };
37 /**
38 * Chunk length
39 */
40 unsigned long length;
41
42 chunk_header_t()
43 : id_number(0), length(0) { }
44 chunk_header_t(const chunk_header_t& s)
45 : id_number(s.id_number), length(s.length) { };
46
47 chunk_header_t& operator=(const chunk_header_t& s) {
48 id_number=s.id_number; length=s.length;
49 return *this;
50 }
51
52 /**
53 * Load chunk header from the stream
54 * @param s input stream
55 */
56 void load(istream& s);
57 /**
58 * Save chunk header to the stream
59 * @param s output stream
60 */
61 void save(ostream& s) const;
62
63 /**
64 * Dump textual representation of chunk header to stream
65 * @param s output stream
66 */
67 void dump(ostream& s) const;
68
69 };
70
71 inline ostream& operator<<(ostream& s,const chunk_header_t& ch) {
72 ch.dump(s); return s;
73 }
74
75 /**
76 * Base class for specific chunk containers
77 */
78 class chunk_t {
79 public:
80 /**
81 * Chunk header data
82 */
83 chunk_header_t header;
84 };
85
86}
87
88#endif /* __MIDILLO_CHUNK_H */