Anonymous avatar Anonymous committed 7ab56d6 Draft

Ability to flatten song's blocks into one big block.

Comments (0)

Files changed (2)

 (Amiga MED module) format.
 
 Right now they are in a very crude state.  The ultimate goal is to have
-something that converts most of the data in them to cSound format, where
+something that converts most of the data in them to Csound format, where
 they can be cleaned up (consistent panning per instrument, and so forth.)
+
+Currently, the `mmd0.py` script can dump most of the contents of an MMD0
+file in a nominally human-readable format, and can extract the samples used
+as the instruments.
+
+As I'm doing this primarily for my own MED tunes, I don't plan to support
+the features of MED that I never personally used, such as synthesized
+instruments.
         for smpl_offset in self.smplarr_offsets:
             self.smplarr.append(InstrHdr(buffer, smpl_offset))
 
+    def flatten(self):
+        """Turn the event data in the blocks in the song sequence
+        into a list of lists of events, one list of events per track.
+
+        """
+        numtracks = None
+        for block in self.blockarr:
+            if numtracks is None:
+                numtracks = block.numtracks
+            else:
+                assert numtracks == block.numtracks, \
+                    "blocks have differing numbers of tracks"
+
+        track = []
+        i = 0
+        while i < numtracks:
+            track.append([])
+            i += 1
+
+        for block_no in self.song.playseq[:self.song.songlen]:
+            block = self.blockarr[block_no]
+            i = 0
+            while i < numtracks:
+                track[i].extend(block.track[i])
+                i += 1
+
+        line_no = 0
+        lines = len(track[0])
+        while line_no < lines:
+            track_no = 0
+            print "    ",
+            while track_no < numtracks:
+                s = str(track[track_no][line_no])
+                print s.ljust(18),
+                track_no += 1
+            print
+            line_no += 1
+
+        return track
+
     def dump(self):
         print "MMD0 Header"
         print "-----------"
     with open(sys.argv[1], 'r') as f:
         b = Buffer(f)
     m = MMD0(b)
-    m.dump()
+    #m.dump()
+    m.flatten()
     if False:
         for byte in m.smplarr[0].data:
             # upsample to 16-bit for aplay's benefit
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.