changeset 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
files musiccutter.py notes orgues-de-barbarie-27.ini
diffstat 3 files changed, 30 insertions(+), 46 deletions(-) [+]
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
--- a/notes	Tue May 24 11:12:20 2016 +0930
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-# List of notes the organ plays in order
-# Any line beginning with a # is a comment
-# http://www.orgues-de-barbarie.com/wp-content/uploads/2014/09/gammes.pdf
-C3
-D3
-F3
-G3
-C4
-D4
-E4
-F4
-F4#
-G4
-A4
-A4#
-B4
-C5
-C5#
-D5
-D5#
-E5
-F5
-F5#
-G5
-G5#
-A5
-A5#
-B5
-C6
-D6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orgues-de-barbarie-27.ini	Tue May 24 19:40:11 2016 +0930
@@ -0,0 +1,15 @@
+[default]
+# All measurements in mm
+name = Orgues de Babarie 27 note
+# Card dimensions
+pagewidth = 120
+pageheight = 155
+# Distance between slot centres
+pitch = 5.5
+# Width of slot
+slotsize = 3.3
+# Distance from bottom of page to centre of slot
+heel = 6.0
+# List of notes the organ plays in order from top of the card to the bottom
+# http://www.orgues-de-barbarie.com/wp-content/uploads/2014/09/gammes.pdf
+notes = C3 D3 F3 G3 C4 D4 E4 F4 F4# G4 A4 A4# B4 C5 C5# D5 D5# E5 F5 F5# G5 G5# A5 A5# B5 C6 D6