|
|
|
@@ -1,52 +1,53 @@ |
1 | #include <iostream> |
1 | #include <iostream> |
2 | #include <fstream> |
2 | #include <fstream> |
3 | #include <algorithm> |
3 | #include <algorithm> |
4 | #include <iterator> |
4 | #include <iterator> |
| |
5 | #include <cstring> |
5 | #include <midillo/SMF.h> |
6 | #include <midillo/SMF.h> |
6 | |
7 | |
7 | namespace midillo { |
8 | namespace midillo { |
8 | using std::ifstream; |
9 | using std::ifstream; |
9 | using std::ofstream; |
10 | using std::ofstream; |
10 | using std::cin; |
11 | using std::cin; |
11 | using std::cout; |
12 | using std::cout; |
12 | using std::copy; |
13 | using std::copy; |
13 | using std::ostream_iterator; |
14 | using std::ostream_iterator; |
14 | using std::endl; |
15 | using std::endl; |
15 | |
16 | |
16 | void SMF_t::load(const char *f,bool stdinable) { |
17 | void SMF_t::load(const char *f,bool stdinable) { |
17 | if(stdinable && !strcmp(f,"-")) { |
18 | if(stdinable && !strcmp(f,"-")) { |
18 | load(cin); |
19 | load(cin); |
19 | }else{ |
20 | }else{ |
20 | ifstream s(f,std::ios::in|std::ios::binary); |
21 | ifstream s(f,std::ios::in|std::ios::binary); |
21 | load(s); |
22 | load(s); |
22 | } |
23 | } |
23 | } |
24 | } |
24 | |
25 | |
25 | void SMF_t::load(istream& s) { |
26 | void SMF_t::load(istream& s) { |
26 | mthd.load(s); |
27 | mthd.load(s); |
27 | tracks.resize(mthd.ntracks); |
28 | tracks.resize(mthd.ntracks); |
28 | tracks_t::iterator i = tracks.begin(); |
29 | tracks_t::iterator i = tracks.begin(); |
29 | for(int t=0;t<mthd.ntracks;++t,++i) { |
30 | for(int t=0;t<mthd.ntracks;++t,++i) { |
30 | i->load(s); |
31 | i->load(s); |
31 | } |
32 | } |
32 | } |
33 | } |
33 | |
34 | |
34 | void SMF_t::save(const char *f,bool stdoutable) const { |
35 | void SMF_t::save(const char *f,bool stdoutable) const { |
35 | if(stdoutable && !strcmp(f,"-")) { |
36 | if(stdoutable && !strcmp(f,"-")) { |
36 | save(cout); |
37 | save(cout); |
37 | }else{ |
38 | }else{ |
38 | ofstream s(f,std::ios::out|std::ios::trunc|std::ios::binary); |
39 | ofstream s(f,std::ios::out|std::ios::trunc|std::ios::binary); |
39 | save(s); |
40 | save(s); |
40 | } |
41 | } |
41 | } |
42 | } |
42 | |
43 | |
43 | void SMF_t::save(ostream& s) const { |
44 | void SMF_t::save(ostream& s) const { |
44 | mthd.save(s); |
45 | mthd.save(s); |
45 | for(tracks_t::const_iterator i=tracks.begin();i!=tracks.end();++i) { |
46 | for(tracks_t::const_iterator i=tracks.begin();i!=tracks.end();++i) { |
46 | i->save(s); |
47 | i->save(s); |
47 | } |
48 | } |
48 | } |
49 | } |
49 | |
50 | |
50 | void SMF_t::dump(ostream& s) const { |
51 | void SMF_t::dump(ostream& s) const { |
51 | std::ios::fmtflags ff = s.flags(); |
52 | std::ios::fmtflags ff = s.flags(); |
52 | s.unsetf(std::ios::hex); s.setf(std::ios::dec); |
53 | s.unsetf(std::ios::hex); s.setf(std::ios::dec); |
|