summaryrefslogtreecommitdiffabout
path: root/lib/event.cc
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 /lib/event.cc
parent9bcc235e575a95989a5903394c127accbeef2e0f (diff)
downloadmidillo-0.0.zip
midillo-0.0.tar.gz
midillo-0.0.tar.bz2
initial commit into repository0.0
Diffstat (limited to 'lib/event.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/event.cc58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/event.cc b/lib/event.cc
new file mode 100644
index 0000000..39438fa
--- a/dev/null
+++ b/lib/event.cc
@@ -0,0 +1,58 @@
1#include <midillo/event.h>
2#include <midillo/util.h>
3
4namespace midillo {
5
6 void event_t::load(int& rs,istream& s) {
7 deltat = readVL(s);
8 message.load(rs,s);
9 }
10
11 void event_t::save(int& rs,ostream& s) const {
12 writeVL(s,deltat);
13 message.save(rs,s);
14 }
15
16 unsigned long event_t::calculate_save_size(int& rs) const {
17 return calcVLsize(deltat) + message.calculate_save_size(rs);
18 }
19
20 void event_t::dump(ostream& s) const {
21 std::ios::fmtflags ff = s.flags();
22 s.unsetf(std::ios::hex); s.setf(std::ios::dec);
23 s << "deltat=" << deltat << " [" << message << "]";
24 s.flags(ff);
25 }
26
27
28 events_t::iterator events_t::append_event() {
29 static event_t empty;
30 return insert(end(),empty);
31 }
32
33 void events_t::load(istream& s) {
34 int rs = -1;
35 for(;;) {
36 iterator i=append_event();
37 i->load(rs,s);
38 if(i->message.is_meta(meta_EOT))
39 break;
40 }
41 }
42
43 void events_t::save(ostream& s) const {
44 int rs = -1;
45 for(const_iterator i=begin();i!=end();++i) {
46 i->save(rs,s);
47 }
48 }
49
50 unsigned long events_t::calculate_save_size() const {
51 unsigned long rv = 0;
52 int rs = -1;
53 for(const_iterator i=begin();i!=end();++i) {
54 rv += i->calculate_save_size(rs);
55 }
56 return rv;
57 }
58}