summaryrefslogtreecommitdiffabout
path: root/lib/SMF.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/SMF.cc
parent9bcc235e575a95989a5903394c127accbeef2e0f (diff)
downloadmidillo-0c21a7a0d5b84dc6726462f0fbe51b8c32433262.zip
midillo-0c21a7a0d5b84dc6726462f0fbe51b8c32433262.tar.gz
midillo-0c21a7a0d5b84dc6726462f0fbe51b8c32433262.tar.bz2
initial commit into repository0.0
Diffstat (limited to 'lib/SMF.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/SMF.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/SMF.cc b/lib/SMF.cc
new file mode 100644
index 0000000..ba3179d
--- a/dev/null
+++ b/lib/SMF.cc
@@ -0,0 +1,62 @@
1#include <iostream>
2#include <fstream>
3#include <algorithm>
4#include <iterator>
5#include <midillo/SMF.h>
6
7namespace midillo {
8 using std::ifstream;
9 using std::ofstream;
10 using std::cin;
11 using std::cout;
12 using std::copy;
13 using std::ostream_iterator;
14 using std::endl;
15
16 void SMF_t::load(const char *f,bool stdinable) {
17 if(stdinable && !strcmp(f,"-")) {
18 load(cin);
19 }else{
20 ifstream s(f,std::ios::in|std::ios::binary);
21 load(s);
22 }
23 }
24
25 void SMF_t::load(istream& s) {
26 mthd.load(s);
27 tracks.resize(mthd.ntracks);
28 tracks_t::iterator i = tracks.begin();
29 for(int t=0;t<mthd.ntracks;++t,++i) {
30 i->load(s);
31 }
32 }
33
34 void SMF_t::save(const char *f,bool stdoutable) const {
35 if(stdoutable && !strcmp(f,"-")) {
36 save(cout);
37 }else{
38 ofstream s(f,std::ios::out|std::ios::trunc|std::ios::binary);
39 save(s);
40 }
41 }
42
43 void SMF_t::save(ostream& s) const {
44 mthd.save(s);
45 for(tracks_t::const_iterator i=tracks.begin();i!=tracks.end();++i) {
46 i->save(s);
47 }
48 }
49
50 void SMF_t::dump(ostream& s) const {
51 std::ios::fmtflags ff = s.flags();
52 s.unsetf(std::ios::hex); s.setf(std::ios::dec);
53 s
54 << "SMF with " << tracks.size() << " track(s)" << endl
55 << mthd << endl;
56 copy(
57 tracks.begin(), tracks.end(),
58 ostream_iterator<MTrk_t>(s,"\n") );
59 s.flags(ff);
60 }
61
62}