diff musiccutter.py @ 41:21da8af1cdd2

Use ini file to hold organ specific details.
author Daniel O'Connor <darius@dons.net.au>
date Tue, 24 May 2016 19:40:11 +0930
parents 5c47f9361d93
children 3925ac56d99e
line wrap: on
line diff
--- a/musiccutter.py	Tue May 24 11:12:20 2016 +0930
+++ b/musiccutter.py	Tue May 24 19:40:11 2016 +0930
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 
 from IPython.core.debugger import Tracer
+import ConfigParser
 import exceptions
 import itertools
 import math
@@ -35,12 +36,7 @@
     # +---+---+---+ highest note
     #
     m = Midi2PDF(**{
-        'notefile' : 'notes',
-        'pagewidth' : 120,
-        'pageheight' : 155,
-        'pitch' : 5.5,
-        'slotsize' : 3.3,
-        'heel' : 6.0,
+        'config' : 'orgues-de-barbarie-27.ini',
         'leadin' : 50,
         'timemarks' : False,
         'trytranspose' : True,
@@ -59,14 +55,14 @@
     m.processMidi(filename, base + '-%02d.pdf')
 
 class Midi2PDF(object):
-    def __init__(self, notefile, pagewidth, pageheight, pitch, slotsize, heel, leadin, timemarks, trytranspose, drawrect, notenames, notelines, noteoffset, pagesperpdf, timescale, notescale, fontname, fontsize):
-        self.midi2note, self.note2midi = Midi2PDF.genmidi2note()
-        self.note2slot, self.slot2note = Midi2PDF.loadnote2slot(notefile, self.note2midi)
-        self.pagewidth = pagewidth # Dimensions are in millimetres
-        self.pageheight = pageheight
-        self.pitch = pitch # Distance between each slot
-        self.slotsize = slotsize # Size of each slot cut out
-        self.heel = heel # Bottom margin (from bottom of page to centre of slot)
+    def __init__(self, config, leadin, timemarks, trytranspose, drawrect, notenames, notelines, noteoffset, pagesperpdf, timescale, notescale, fontname, fontsize):
+        cp = ConfigParser.ConfigParser()
+        cp.read(config)
+        self.pagewidth = cp.getfloat('default', 'pagewidth')
+        self.pageheight = cp.getfloat('default', 'pageheight')
+        self.pitch = cp.getfloat('default', 'pitch')
+        self.slotsize = cp.getfloat('default', 'slotsize')
+        self.heel = cp.getfloat('default', 'heel')
         self.leadin = leadin # Extra at the start
         self.timemarks = timemarks # Draw vertical time lines
         self.trytranspose = trytranspose # Attempt to tranpose unplayable notes
@@ -82,6 +78,9 @@
 
         self.pdfwidth = self.pagewidth * self.pagesperpdf
 
+        self.midi2note, self.note2midi = Midi2PDF.genmidi2note()
+        self.note2slot, self.slot2note = Midi2PDF.loadnote2slot(cp.get('default', 'notes').split(), self.note2midi)
+
     def processMidi(self, midifile, outpat):
         stats = Stats()
         stats.playablecount = 0
@@ -266,12 +265,12 @@
         return midi2note, note2midi
 
     @staticmethod
-    def loadnote2slot(fname, note2midi):
+    def loadnote2slot(notelist, note2midi):
         note2slot = {}
         slot2note = {}
         index = 0
 
-        for note in file(fname):
+        for note in notelist:
             note = note.strip()
             if note[0] == '#':
                 continue