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) (side-by-side diff)
tree9df6334cb1a61efebe68f7bcef9aa119a823626a /lib/SMF.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/SMF.cc') (more/less context) (show 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 @@
+#include <iostream>
+#include <fstream>
+#include <algorithm>
+#include <iterator>
+#include <midillo/SMF.h>
+
+namespace midillo {
+ using std::ifstream;
+ using std::ofstream;
+ using std::cin;
+ using std::cout;
+ using std::copy;
+ using std::ostream_iterator;
+ using std::endl;
+
+ void SMF_t::load(const char *f,bool stdinable) {
+ if(stdinable && !strcmp(f,"-")) {
+ load(cin);
+ }else{
+ ifstream s(f,std::ios::in|std::ios::binary);
+ load(s);
+ }
+ }
+
+ void SMF_t::load(istream& s) {
+ mthd.load(s);
+ tracks.resize(mthd.ntracks);
+ tracks_t::iterator i = tracks.begin();
+ for(int t=0;t<mthd.ntracks;++t,++i) {
+ i->load(s);
+ }
+ }
+
+ void SMF_t::save(const char *f,bool stdoutable) const {
+ if(stdoutable && !strcmp(f,"-")) {
+ save(cout);
+ }else{
+ ofstream s(f,std::ios::out|std::ios::trunc|std::ios::binary);
+ save(s);
+ }
+ }
+
+ void SMF_t::save(ostream& s) const {
+ mthd.save(s);
+ for(tracks_t::const_iterator i=tracks.begin();i!=tracks.end();++i) {
+ i->save(s);
+ }
+ }
+
+ void SMF_t::dump(ostream& s) const {
+ std::ios::fmtflags ff = s.flags();
+ s.unsetf(std::ios::hex); s.setf(std::ios::dec);
+ s
+ << "SMF with " << tracks.size() << " track(s)" << endl
+ << mthd << endl;
+ copy(
+ tracks.begin(), tracks.end(),
+ ostream_iterator<MTrk_t>(s,"\n") );
+ s.flags(ff);
+ }
+
+}