Commits

daybreaker  committed 72390ab

initial commit

  • Participants

Comments (0)

Files changed (2)

+#! /usr/bin/env python
+# -*- coding: utf8 -*-
+#
+# Noteworthy Composer Text Format Converter
+# (Korean version)
+import sys
+
+position_bases = {
+    'Treble': 67,  # 가온 다 오른쪽 첫번째 B(시)음
+    'Bass': 49,    # 가온 다 왼쪽 첫번째 D(레)음
+}
+# We cannot distinguish major and minor keys currently.
+keysig_map = {
+    '0': 'c \major',
+    '#1': 'g \major',
+    '#2': 'd \major',
+    '#3': 'a \major',
+    '#4': 'e \major',
+    '#5': 'b \major',
+    '#6': 'fis \major',
+    '#7': 'cis \major',
+    'b1': 'f \major',
+    'b2': 'bes \major',
+    'b3': 'ees \major',
+    'b4': 'aes \major',
+    'b5': 'des \major',
+    'b6': 'ges \major',
+    'b7': 'ces \major',
+}
+accidental_map = {
+    '#': 'is',
+    'x': 'isis',
+    'b': 'es',
+    'v': 'eses',
+}
+barline_map = {
+    'Single': '|',
+    'Double': '||',
+    'SectionOpen': '.|',
+    'SecionClose': '|.',
+    'MasterRepeatOpen': '|:',
+    'MasterRepeatClose': ':|',
+    'CloseRepeatOpen': '|:',
+    'CloseRepeatClose': ':|',
+}
+
+# Assumptions:
+# - All staves have the same time signature and the same key signature.
+#   (including intermediate changes)
+#   Exceptions may apply for percussion staves.
+# - All staves share a single global tempo.
+# - 
+
+def usage():
+    print 'blah blah'
+
+def parse_parts(parts):
+    data = {}
+    for item in parts:
+        k, v = item.split(':')
+        if v == 'Y':
+            v = True
+        elif v == 'N':
+            v = False
+        if v.startswith('"') and v.endswith('"'):
+            v = v[1:-1].replace('\\r\\n', '\r\n').decode('cp949')
+        data[k] = v
+    return data
+
+def parse_opts(value):
+    data = {}
+    for item in data.split(','):
+        try:
+            k, v = item.split('=')
+        except ValueError:
+            k = item
+            v = True
+        data[k] = v
+    return data
+
+def absolute_pos(relative_pos, clef='Treble'):
+    return position_bases[clef] + relative_pos
+
+def normalize_name(name):
+    # TODO
+    return name.replace(' ', '_')
+
+def convert_key(keysig):
+    sharps = keysig.count('#')
+    flats = keysig.count('b')
+    if sharps == 0 and flats == 0:
+        return keysig_map['0']
+    if sharps > 0 and flats == 0:
+        return keysig_map['#' + str(sharps)]
+    if sharps == 0 and flats > 0:
+        return keysig_map['b' + str(flats)]
+    else:
+        print 'WARNING: unsupported keysignature (%s)' % keysig
+    return None
+
+def convert(input_file, output_file):
+    staff_began = False
+    layered = False
+    for line in input_file:
+        if line.startswith('!'):  # comment lines
+            continue
+        parts = line.strip().split('|')
+        object_type = parts[1]
+        data = parse_parts(parts[2:])
+        print object_type, data
+        if object_type == 'SongInfo':
+            pass
+        if object_type == 'PgSetup':
+            pass
+        if object_type == 'Font':
+            pass
+        if object_type == 'PgMargins':
+            pass
+        if object_type == 'AddStaff':
+            data['Style']
+            data['Layer']
+            if staff_began:
+                pass
+            else:
+                pass
+        if object_type == 'StaffProperties':
+            pass
+        if object_type == 'StaffInstrument':
+            pass
+        if object_type == 'Lyrics':
+            pass
+        if object_type.startswith('Lyric'):
+            pass
+        if object_type == 'Clef':
+            pass
+        if object_type == 'TimeSig':
+            pass
+        if object_type == 'Key':
+            pass
+        if object_type == 'Tempo':
+            data.get('Text', '')
+            pass
+        if object_type == 'Rest':
+            pass
+        if object_type == 'Bar':
+            pass
+        if object_type == 'Text':
+            pass
+        if object_type == 'Note':
+            dur = data['Dur'].split(',')
+            dur_opts = parse_opts(dur[1:])
+            pass
+        if object_type == 'Chord':
+            pass
+        if object_type == 'Dynamic':
+            data['Style']
+            pass
+        if object_type == 'SustainPedal':
+            pass
+        if object_type == 'PerformanceStyle':
+            pass
+        if object_type == 'Flow':
+            pass
+
+if __name__ == '__main__':
+    if len(sys.argv) == 1:
+        usage()
+    else:
+        input_file = open(sys.argv[1], 'r')
+        try:
+            output_file = open(sys.argv[2], 'w')
+        except IndexError:
+            output_file = sys.stdout
+
+    convert(input_file, output_file)
+    input_file.close()
+    if output_file != sys.stdout:
+        output_file.close()
+    print 'Conversion complete!'

File sample1.nwctxt

+!NoteWorthyComposer(2.0)
+|SongInfo|Title:"nwctxt2ly �׽�Ʈ"|Author:"���ر�"|Lyricist:""|Copyright1:"Copyright ? 2010 by Joongi Kim"|Copyright2:"All Rights Reserved"|Comments:"���!"
+|PgSetup|StaffSize:11|Zoom:4|TitlePage:Y|JustifyVertically:Y|ExtendLastSystem:N|DurationPadding:Y|PageNumbers:1|StaffLabels:Top Systems|BarNumbers:Boxed|StartingBar:1
+|Font|Style:Staff Italic|Typeface:"Times New Roman"|Size:7|Bold:Y|Italic:Y|CharSet:0
+|Font|Style:Staff Bold|Typeface:"Times New Roman"|Size:5|Bold:Y|Italic:N|CharSet:0
+|Font|Style:Staff Lyric|Typeface:"Times New Roman"|Size:5|Bold:N|Italic:N|CharSet:0
+|Font|Style:Page Title Text|Typeface:"Times New Roman"|Size:24|Bold:Y|Italic:N|CharSet:0
+|Font|Style:Page Text|Typeface:"Times New Roman"|Size:12|Bold:N|Italic:N|CharSet:0
+|Font|Style:Page Small Text|Typeface:"Times New Roman"|Size:8|Bold:N|Italic:N|CharSet:0
+|Font|Style:User 1|Typeface:"Times New Roman"|Size:5|Bold:N|Italic:N|CharSet:0
+|Font|Style:User 2|Typeface:"Times New Roman"|Size:5|Bold:N|Italic:N|CharSet:0
+|Font|Style:User 3|Typeface:"Times New Roman"|Size:5|Bold:N|Italic:N|CharSet:0
+|Font|Style:User 4|Typeface:"Times New Roman"|Size:5|Bold:N|Italic:N|CharSet:0
+|Font|Style:User 5|Typeface:"Times New Roman"|Size:8|Bold:N|Italic:N|CharSet:0
+|Font|Style:User 6|Typeface:"Times New Roman"|Size:8|Bold:N|Italic:N|CharSet:0
+|PgMargins|Left:2.54|Top:2.54|Right:2.54|Bottom:2.54|Mirror:N
+|AddStaff|Name:"Violino I."|Label:"Violino I."|Group:"Standard"
+|StaffProperties|EndingBar:Section Close|Visible:Y|BoundaryTop:18|BoundaryBottom:13|Lines:5|Style:Orchestral|Layer:N|Color:Default
+|StaffProperties|Muted:N|Volume:127|StereoPan:64|Device:0|Channel:2
+|StaffInstrument|Patch:40|Trans:0|DynVel:10,30,45,60,75,92,108,127
+|Clef|Type:Treble
+|Key|Signature:F#,C#,G#,D#,A#
+|TimeSig|Signature:Common
+|Tempo|Base:Eighth|Tempo:120|Text:"Custom Tempo"|Pos:14
+|Dynamic|Style:mp|Pos:-10
+|PerformanceStyle|Style:Cantabile|Pos:9
+|Note|Dur:4th,Slur|Pos:-2
+|Note|Dur:4th,Slur|Pos:-1
+|Note|Dur:4th,Slur|Pos:-2
+|Chord|Dur:8th|Pos:-5|Opts:Stem=Down,Beam=First|Dur2:4th|Pos2:-3
+|Note|Dur:8th|Pos:-4|Opts:Stem=Down,Beam=End
+|Bar
+|Note|Dur:8th,Triplet=First,Slur|Pos:-4|Opts:Stem=Up,Crescendo,Slur=Upward,Beam=First
+|Note|Dur:8th,Triplet,Slur|Pos:-3|Opts:Stem=Up,Crescendo,Slur=Upward,Beam
+|Note|Dur:8th,Triplet=End,Slur|Pos:-2|Opts:Stem=Up,Crescendo,Slur=Upward,Beam=End
+|Note|Dur:16th,Triplet=First,Slur|Pos:-1|Opts:Stem=Down,Crescendo,Slur=Upward,Beam=First
+|Note|Dur:16th,Triplet,Slur|Pos:0|Opts:Stem=Down,Crescendo,Slur=Upward,Beam
+|Note|Dur:16th,Triplet=End,Slur|Pos:1|Opts:Stem=Down,Crescendo,Slur=Upward,Beam
+|Note|Dur:16th,Triplet=First,Slur|Pos:0|Opts:Stem=Down,Crescendo,Slur=Upward,Beam
+|Note|Dur:16th,Triplet,Slur|Pos:1|Opts:Stem=Down,Crescendo,Slur=Upward,Beam
+|Note|Dur:16th,Triplet=End,Slur|Pos:2|Opts:Stem=Down,Crescendo,Slur=Upward,Beam=End
+|Note|Dur:4th,Accent|Pos:-2|Opts:Diminuendo
+|Note|Dur:4th,Staccato|Pos:-4
+|Bar|Style:Double
+|Key|Signature:F#,C#
+|Dynamic|Style:mf|Pos:-11
+|Tempo|Tempo:60|Pos:11
+|Note|Dur:4th,Slur|Pos:5
+|Note|Dur:4th,Slur|Pos:6
+|Note|Dur:4th,Slur|Pos:5
+|Note|Dur:4th|Pos:4
+|Bar
+|Chord|Dur:8th,Slur|Pos:1|Opts:Stem=Down,Beam=First|Dur2:Whole|Pos2:3^
+|Note|Dur:8th,Slur|Pos:0|Opts:Stem=Down,Beam
+|Note|Dur:8th,Slur|Pos:-1|Opts:Stem=Down,Beam
+|Note|Dur:8th|Pos:-2|Opts:Stem=Down,Beam=End
+|Note|Dur:8th,Slur|Pos:-4|Opts:Stem=Down,Beam=First
+|Note|Dur:8th,Slur|Pos:-2|Opts:Stem=Down,Beam
+|Note|Dur:8th,Slur|Pos:-1|Opts:Stem=Down,Beam
+|Note|Dur:8th|Pos:0|Opts:Stem=Down,Beam=End
+|Bar
+|Note|Dur:Half|Pos:3
+|Rest|Dur:Half
+|Bar|Style:Double
+|Key|Signature:Bb,Eb
+|Bar|Style:MasterRepeatClose
+|AddStaff|Name:"Violino II."|Label:"Violino II."|Group:"Standard"
+|StaffProperties|EndingBar:Section Close|Visible:Y|BoundaryTop:15|BoundaryBottom:13|Lines:5|Style:Orchestral|Layer:N|Color:Default
+|StaffProperties|Muted:N|Volume:127|StereoPan:64|Device:0|Channel:3
+|StaffInstrument|Patch:40|Trans:0|DynVel:10,30,45,60,75,92,108,127
+|Clef|Type:Treble
+|Key|Signature:F#,C#,G#,D#,A#
+|TimeSig|Signature:Common
+|Rest|Dur:Whole
+|Bar
+|Rest|Dur:Whole
+|Bar|Style:Double
+|Key|Signature:F#,C#
+|AddStaff|Name:"Viola."|Label:"Viola."|Group:"Standard"
+|StaffProperties|EndingBar:Section Close|Visible:Y|BoundaryTop:15|BoundaryBottom:13|Lines:5|Style:Orchestral|Layer:N|Color:Default
+|StaffProperties|Muted:N|Volume:127|StereoPan:64|Device:0|Channel:4
+|StaffInstrument|Patch:41|Trans:0|DynVel:10,30,45,60,75,92,108,127
+|Clef|Type:Alto
+|Key|Signature:F#,C#,G#,D#,A#
+|TimeSig|Signature:Common
+|Dynamic|Style:f|Pos:-8
+|Rest|Dur:4th
+|Note|Dur:4th,Staccato|Pos:3
+|Rest|Dur:4th
+|Note|Dur:4th,Staccato|Pos:3
+|Bar
+|Rest|Dur:4th
+|Note|Dur:4th,Staccato|Pos:6
+|Rest|Dur:4th
+|Note|Dur:4th,Staccato|Pos:6
+|Bar|Style:Double
+|Key|Signature:F#,C#
+|AddStaff|Name:"Violoncello."|Label:"Violoncello."|Group:"Standard"
+|StaffProperties|EndingBar:Section Close|Visible:Y|BoundaryTop:13|BoundaryBottom:15|Lines:5|Style:Orchestral|Layer:N|Color:Default
+|StaffProperties|Muted:N|Volume:127|StereoPan:64|Device:0|Channel:5
+|StaffInstrument|Patch:42|Trans:0|DynVel:10,30,45,60,75,92,108,127
+|Clef|Type:Bass
+|Key|Signature:F#,C#,G#,D#,A#
+|TimeSig|Signature:Common
+|Dynamic|Style:mp|Pos:-9
+|Note|Dur:4th,Slur|Pos:#-4
+|Note|Dur:4th,Slur|Pos:0
+|Note|Dur:4th,Slur|Pos:3
+|Note|Dur:4th|Pos:x5
+|Bar
+|Note|Dur:4th,Slur|Pos:-1
+|Note|Dur:4th,Slur|Pos:n1
+|Note|Dur:4th,Slur|Pos:3
+|Note|Dur:4th|Pos:v6
+|Bar|Style:Double
+|Key|Signature:F#,C#
+|AddStaff|Name:"Right Hand"|Label:"Piano (R.H.)"|Group:"Standard"
+|StaffProperties|EndingBar:Section Close|Visible:Y|BoundaryTop:15|BoundaryBottom:10|Lines:5|Style:Upper Grand Staff|Layer:Y|Color:Default
+|StaffProperties|Muted:N|Volume:127|StereoPan:64|Device:0|Channel:6
+|StaffInstrument|Patch:0|Trans:0|DynVel:10,30,45,60,75,92,108,127
+|Clef|Type:Treble
+|Key|Signature:F#,C#,G#,D#,A#
+|TimeSig|Signature:Common
+|Dynamic|Style:f|Pos:-8
+|PerformanceStyle|Style:Legato|Pos:-14
+|Note|Dur:Half,Tenuto|Pos:5|Opts:Stem=Up
+|Note|Dur:Half,Tenuto|Pos:2|Opts:Stem=Up
+|Bar
+|Note|Dur:4th,DblDotted,Slur|Pos:3
+|Note|Dur:16th|Pos:1
+|Note|Dur:4th,DblDotted,Slur|Pos:5
+|Note|Dur:16th|Pos:3
+|Bar|Style:Double
+|Key|Signature:F#,C#
+|Clef|Type:Treble|OctaveShift:Octave Up
+|Note|Dur:Half,Tenuto|Pos:5|Opts:Stem=Up
+|Note|Dur:Half,Tenuto|Pos:2|Opts:Stem=Up
+|Bar
+|Note|Dur:4th,DblDotted,Slur|Pos:3
+|Note|Dur:16th|Pos:1
+|Note|Dur:4th,DblDotted,Slur|Pos:5
+|Note|Dur:16th,Slur|Pos:3
+|Bar
+|Note|Dur:Half|Pos:-2
+|Rest|Dur:Half
+|Bar|Style:MasterRepeatClose
+|AddStaff|Name:"Right Hand 2"|Group:"Standard"
+|StaffProperties|EndingBar:Section Close|Visible:Y|BoundaryTop:15|BoundaryBottom:10|Lines:5|Style:Upper Grand Staff|Layer:N|Color:Default
+|StaffProperties|Muted:N|Volume:127|StereoPan:64|Device:0|Channel:6
+|StaffInstrument|Name:"Acoustic Grand Piano"|Patch:0|Trans:0|DynVel:10,30,45,60,75,92,108,127
+|Clef|Type:Treble
+|Key|Signature:F#,C#,G#,D#,A#
+|TimeSig|Signature:Common
+|SustainPedal|Pos:-8|Wide:Y|Visibility:Never
+|Note|Dur:8th,Slur|Pos:0|Opts:Stem=Down,Slur=Downward,Beam=First
+|Note|Dur:8th,Slur|Pos:1|Opts:Stem=Down,Slur=Downward,Beam
+|Note|Dur:8th,Slur|Pos:2|Opts:Stem=Down,Slur=Downward,Beam
+|Note|Dur:8th|Pos:3|Opts:Stem=Down,Beam=End
+|Note|Dur:8th,Slur|Pos:-2|Opts:Stem=Down,Beam=First,Tie=Downward
+|Note|Dur:8th,Slur|Pos:-1|Opts:Stem=Down,Beam,Tie=Downward
+|Note|Dur:8th,Slur|Pos:0|Opts:Stem=Down,Beam,Tie=Downward
+|Note|Dur:8th|Pos:1|Opts:Stem=Down,Beam=End
+|SustainPedal|Status:Released|Pos:-8|Wide:Y|Visibility:Never
+|Bar
+|Rest|Dur:Whole|Visibility:TopStaff
+|Bar|Style:Double
+|Key|Signature:C
+|AddStaff|Name:"Left Hand"|Label:"Piano (L.H.)"|Group:"Standard"
+|StaffProperties|EndingBar:Section Close|Visible:Y|BoundaryTop:10|BoundaryBottom:10|Lines:5|Style:Lower Grand Staff|Layer:N|Color:Default
+|StaffProperties|Muted:N|Volume:127|StereoPan:64|Device:0|Channel:7
+|StaffInstrument|Patch:0|Trans:0|DynVel:10,30,45,60,75,92,108,127
+|Clef|Type:Bass
+|Key|Signature:F#,C#,G#,D#,A#
+|TimeSig|Signature:Common
+|SustainPedal|Pos:-8|Wide:Y
+|Note|Dur:8th,Grace,Slur|Pos:3
+|Note|Dur:Whole|Pos:-4
+|SustainPedal|Status:Released|Pos:-8|Wide:Y
+|Bar
+|SustainPedal|Pos:-8|Wide:Y
+|Note|Dur:8th,Grace,Slur|Pos:3
+|Note|Dur:Whole|Pos:-4
+|SustainPedal|Status:Released|Pos:-8|Wide:Y
+|Bar|Style:Double
+|Key|Signature:F#,C#
+!NoteWorthyComposer-End