Anonymous avatar Anonymous committed d8e9af7

future refactoring notes

Comments (0)

Files changed (1)

         print 'WARNING: unsupported keysignature (%s)' % keysig
     return None
 
-def convert(input_file, output_file):
+def convert_in_context(ctx, token_type, token_data):
+    # TODO: This structure can be used at Python scripts for the 'User Tools' feature in NWC 2.0 or later.
+    pass
+
+def convert_file(input_file, output_file):
     staff_began = False
     num_staves, num_processed_staves = 0, 0
     num_notes, num_bars = 0, 0
         if line.startswith('!'):  # comment lines
             continue
         parts = line.strip().split('|')
-        object_type = parts[1]
+        token_type = parts[1]
         data = parse_parts(parts[2:])
-        #print object_type, data
-        if object_type == 'SongInfo':
+        #print token_type, data
+        if token_type == 'SongInfo':
             output_file.write('\\header {\n')
             output_file.write(''.join([
                 '\ttitle = "%s"\n' % data['Title'],
                 '\t%%{ %s %%}\n' % data['Comments'],
             ]))
             output_file.write('\\}\n')
-        if object_type == 'PgSetup':
+        if token_type == 'PgSetup':
             print 'skipping page setup...'
-        if object_type == 'Font':
+        if token_type == 'Font':
             print 'skipping font configuration...'
-        if object_type == 'PgMargins':
+        if token_type == 'PgMargins':
             print 'skipping page margins...'
-        if object_type == 'AddStaff':
+        if token_type == 'AddStaff':
             # followed by several StaffProperties lines and StaffInstrument line
             if staff_began:
                 num_processed_staves += 1
             staff_midi_channel = None
             staff_lines = None
             num_bars, num_notes = 0, 0
-        if object_type == 'StaffProperties':
+        if token_type == 'StaffProperties':
             if staff_style is None:
                 staff_style = data.get('Style', 'Standard')
             if staff_layered is None:
                 staff_muted = data.get('Muted', False)
             if staff_midi_channel is None:
                 staff_midi_channel = data.get('Channel', 1)  # TODO: support percussions?
-        if object_type == 'StaffInstrument':
+        if token_type == 'StaffInstrument':
             pass
             if staff_midi_channel == 10 or staff_midi_channel == 13:
                 print 'WARNING: unsupported staff (percussion channel)'
                 last_clef = ''
                 last_note_pos = ''
                 last_dur = ''
-        if object_type == 'Lyrics':
+        if token_type == 'Lyrics':
             pass
-        if object_type.startswith('Lyric'):
+        if token_type.startswith('Lyric'):
             pass
         if staff_began:
-            if object_type == 'Clef':
+            # context includes staff properties and fake/emulated surroundings
+            # such as clef, timesig, keysig, and tempo.
+            # TODO: convert_in_context(context, token_type, data)
+            if token_type == 'Clef':
                 pass
-            if object_type == 'TimeSig':
+            if token_type == 'TimeSig':
                 pass
-            if object_type == 'Key':
+            if token_type == 'Key':
                 pass
-            if object_type == 'Tempo':
+            if token_type == 'Tempo':
                 data.get('Text', '')
                 pass
-            if object_type == 'Rest':
+            if token_type == 'Rest':
                 pass
-            if object_type == 'Bar':
+            if token_type == 'Bar':
                 pass
                 num_bars += 1
-            if object_type == 'Text':
+            if token_type == 'Text':
                 pass
-            if object_type == 'Note':
+            if token_type == 'Note':
                 dur = data['Dur'].split(',')
                 dur_opts = parse_opts(''.join(dur[1:]))
                 pass
                 num_notes += 1
-            if object_type == 'Chord':
+            if token_type == 'Chord':
                 pass
                 num_notes += 1
-            if object_type == 'Dynamic':
+            if token_type == 'Dynamic':
                 data['Style']
                 pass
-            if object_type == 'SustainPedal':
+            if token_type == 'SustainPedal':
                 pass
-            if object_type == 'PerformanceStyle':
+            if token_type == 'PerformanceStyle':
                 pass
-            if object_type == 'Flow':
+            if token_type == 'Flow':
                 pass
-            if object_type == 'Text':
+            if token_type == 'Text':
                 pass
         else:
             continue
         except IndexError:
             output_file = sys.stdout
 
-    convert(input_file, output_file)
+    convert_file(input_file, output_file)
     input_file.close()
     if output_file != sys.stdout:
         output_file.close()
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.