Skip to content

Commit b126576

Browse files
committedAug 25, 2021
Small fixes
- fixes not being able to type after C'
1 parent e0387a6 commit b126576

File tree

4 files changed

+49
-63
lines changed

4 files changed

+49
-63
lines changed
 

‎abc_styler.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def OnStyleNeeded(self, event):
8383

8484
char_count = 0
8585
for i in xrange(i, end):
86-
# chNext = chr(get_char_at(i+1))
8786
try:
8887
chNext = next_buffer[buffer_pos]
8988
buffer_pos += 1
@@ -166,7 +165,7 @@ def OnStyleNeeded(self, event):
166165
#elif state not in [STYLE_LYRICS, STYLE_BAR, STYLE_COMMENT_NORMAL, STYLE_COMMENT_SPECIAL, STYLE_FIELD_INDEX]:
167166
# state = STYLE_DEFAULT # force to go back to STYLE_DEFAULT if in none of the previous case
168167

169-
if old_state != state: # and char_count > 0:
168+
if old_state != state:
170169
set_styling(char_count, old_state)
171170
char_count = 0
172171
old_state = state

‎easy_abc.py

+47-51
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#
22

3-
program_name = 'EasyABC 1.3.7.9 2021-07-20'
3+
program_name = 'EasyABC 1.3.7.9 2021-08-25'
44

55
# Copyright (C) 2011-2014 Nils Liberg (mail: kotorinl at yahoo.co.uk)
6-
# Copyright (C) 2015-2020 Seymour Shlien (mail: fy733@ncf.ca), Jan Wybren de Jong (jw_de_jong at yahoo dot com)
6+
# Copyright (C) 2015-2021 Seymour Shlien (mail: fy733@ncf.ca), Jan Wybren de Jong (jw_de_jong at yahoo dot com)
77
#
88
# This program is free software: you can redistribute it and/or modify
99
# it under the terms of the GNU Lesser General Public License as published by
@@ -37,7 +37,7 @@
3737
# pass
3838

3939
import sys
40-
PY3 = sys.version_info.major > 2
40+
PY3 = sys.version_info >= (3,0,0)
4141

4242
abcm2ps_default_encoding = 'utf-8' ## 'latin-1'
4343
import codecs
@@ -73,7 +73,7 @@ def unicode(s):
7373
import subprocess
7474
import hashlib
7575

76-
if PY3:
76+
if sys.version_info >= (3,0,0):
7777
from urllib.parse import urlparse, urlencode, urlunparse, parse_qsl, quote # py3
7878
from urllib.request import urlopen, Request, urlretrieve
7979
from urllib.error import HTTPError, URLError
@@ -132,8 +132,9 @@ def unicode(s):
132132
import itertools
133133
from aligner import align_lines, extract_incipit, bar_sep, bar_sep_without_space, get_bar_length, bar_and_voice_overlay_sep
134134
##from midi_processing import humanize_midi
135-
if PY3:
135+
if sys.version_info >= (3,0,0):
136136
from queue import Queue # 1.3.6.2 [JWdJ] 2015-02
137+
Empty = Queue.Empty
137138
else:
138139
from Queue import Queue # 1.3.6.2 [JWdJ] 2015-02
139140

@@ -317,6 +318,12 @@ def remove(self, tune_id):
317318
line_end_re = re.compile('\r\n|\r|\n')
318319
tune_index_re = re.compile(r'^X:\s*(\d+)')
319320

321+
def note_to_index(abc_note):
322+
try:
323+
return all_notes.index(abc_note)
324+
except ValueError:
325+
return None
326+
320327
def text_to_lines(text):
321328
return line_end_re.split(text)
322329

@@ -411,7 +418,7 @@ def get_ghostscript_path():
411418
This function may not see the 64-bit ghostscript installations, especially
412419
if Python was compiled as a 32-bit application.
413420
'''
414-
if PY3:
421+
if sys.version_info >= (3,0,0):
415422
import winreg
416423
else:
417424
import _winreg as winreg
@@ -1837,7 +1844,7 @@ def run(self):
18371844
else:
18381845
wx.CallAfter(self.tick2.Play)
18391846
i += 1 #FAU: 20210102: One tick was missing the first time so incrementing i after the tick
1840-
1847+
18411848
time_offset = self.timedelta_microseconds(datetime.now() - start_time)
18421849
if self.midi_in_poll:
18431850
if wx.Platform == "__WXMAC__":
@@ -1861,7 +1868,7 @@ def run(self):
18611868
end = float(time_offset) / self.beat_duration
18621869
self.notes.append([midi_note, start, end])
18631870
#print('note-off', midi_note, float(time_offset)/self.beat_duration)
1864-
1871+
18651872

18661873
finally:
18671874
#print('FAU: closing')
@@ -3779,7 +3786,7 @@ def __init__(self, parent, ID, app_dir, settings):
37793786
try:
37803787
self.mc = FluidSynthPlayer(soundfont_path)
37813788
except Exception as e:
3782-
error_msg = ''.join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])) + os.linesep + os.linesep.join(errors)
3789+
error_msg = ''.join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]))
37833790
self.mc = None
37843791

37853792
if self.mc is None:
@@ -3794,7 +3801,8 @@ def __init__(self, parent, ID, app_dir, settings):
37943801
backend = wx.media.MEDIABACKEND_WMP10
37953802
self.mc = WxMediaPlayer(self, backend)
37963803
except NotImplementedError:
3797-
self.mc = DummyMidiPlayer() # if media player not supported on this platform
3804+
from midiplayer import DummyMidiPlayer
3805+
self.mc = DummyMidiPlayer() # if media player not supported on this platform
37983806

37993807
self.mc.OnAfterLoad += self.OnMediaLoaded
38003808
self.mc.OnAfterStop += self.OnAfterStop
@@ -4263,8 +4271,7 @@ def OnMouseWheel(self, evt):
42634271

42644272
def play(self):
42654273
if self.settings.get('follow_score', False) and self.current_page_index != 0:
4266-
self.current_page_index = 0
4267-
self.UpdateMusicPane()
4274+
self.select_page(0)
42684275
wx.CallAfter(self.mc.Play)
42694276

42704277
def stop_playing(self):
@@ -4485,8 +4492,7 @@ def FollowScore(self, offset, queue_number):
44854492
if future_time_slice is not None:
44864493
try:
44874494
if future_time_slice.page != self.current_page_index:
4488-
self.current_page_index = future_time_slice.page
4489-
self.UpdateMusicPane()
4495+
self.select_page(future_time_slice.page)
44904496
self.scroll_to_notes(self.music_pane.current_page, future_time_slice.indices)
44914497
elif future_time_slice.svg_row != self.last_played_svg_row and future_time_slice.indices:
44924498
self.last_played_svg_row = future_time_slice.svg_row
@@ -4521,7 +4527,7 @@ def OnRecordMetreSelected(self, evt):
45214527
menu = evt.EventObject
45224528
item = menu.FindItemById(evt.GetId())
45234529
self.settings['record_metre'] = item.GetItemLabelText()
4524-
4530+
45254531

45264532
# 1.3.6.3 [SS] 2015-05-03
45274533
def flip_tempobox(self, state):
@@ -5056,19 +5062,6 @@ def export_html(self, tune, filepath):
50565062
def OnExportAllHTML(self, evt):
50575063
self.export_tunes(_('HTML file'), '.html', self.export_html, only_selected=False, single_file=True)
50585064

5059-
def createArchive(self, rootDir, outputPath):
5060-
cwd = os.getcwd()
5061-
os.chdir(rootDir)
5062-
fout.write('mimetype', compress_type = zipfile.ZIP_STORED)
5063-
fileList = [os.path.join('META-INF', 'container.xml'), os.path.join('OEBPS', 'content.opf')]
5064-
for itemPath in EpubBook.__listManifestItems(os.path.join('OEBPS', 'content.opf')):
5065-
fileList.append(os.path.join('OEBPS', itemPath))
5066-
for filePath in fileList:
5067-
fout.write(filePath, compress_type = zipfile.ZIP_DEFLATED)
5068-
fout.close()
5069-
os.chdir(cwd)
5070-
5071-
50725065
def OnExportAllEpub(self, evt):
50735066
tunes = []
50745067
for i in range(self.tune_list.GetItemCount()):
@@ -6306,8 +6299,7 @@ def ScrollMusicPaneToMatchEditor(self, select_closest_note=False, select_closest
63066299
break
63076300

63086301
if new_page_index is not None and new_page_index != self.current_page_index:
6309-
self.current_page_index = new_page_index
6310-
self.UpdateMusicPane()
6302+
self.select_page(new_page_index)
63116303

63126304
closest_xy = None
63136305
closest_col = -9999
@@ -6409,7 +6401,7 @@ def DoReMiToNote(self, char):
64096401
if matches:
64106402
K = matches[-1]
64116403
doremi_index = doremi_prefixes.index(char)
6412-
base_note_index = all_notes.index(K.upper())
6404+
base_note_index = note_to_index(K.upper())
64136405
note = all_notes[base_note_index + doremi_index]
64146406
if char == char.upper():
64156407
return note[0].upper()
@@ -6418,8 +6410,7 @@ def DoReMiToNote(self, char):
64186410
return char
64196411

64206412
def OnCharEvent(self, evt):
6421-
style = self.editor.GetStyleAt(self.editor.GetCurrentPos())
6422-
is_default_style = (style in [self.styler.STYLE_DEFAULT, self.styler.STYLE_GRACE])
6413+
in_music_code = self.position_is_music_code(self.editor.GetCurrentPos())
64236414

64246415
# 1.3.7 [JWdJ] 2016-01-06
64256416
if self.current_svg_tune and evt.KeyCode in [wx.WXK_PAGEDOWN, wx.WXK_PAGEUP, wx.WXK_HOME, wx.WXK_END]:
@@ -6435,8 +6426,7 @@ def OnCharEvent(self, evt):
64356426
new_page = self.current_page_index - 1
64366427

64376428
if 0 <= new_page < self.current_svg_tune.page_count and new_page != self.current_page_index:
6438-
self.current_page_index = new_page
6439-
self.UpdateMusicPane()
6429+
self.select_page(new_page)
64406430
evt.Skip()
64416431
return
64426432

@@ -6452,7 +6442,8 @@ def OnCharEvent(self, evt):
64526442

64536443
at_end_of_line = not self.editor.GetTextRange(self.editor.GetCurrentPos(), self.editor.GetLineEndPosition(self.editor.GetCurrentLine())).strip('| : ] [')
64546444

6455-
if self.mni_TA_active.IsChecked() and not is_inside_field and is_default_style:
6445+
use_typing_assist = self.mni_TA_active.IsChecked()
6446+
if use_typing_assist and not is_inside_field and in_music_code:
64566447
if c == ' ':
64576448
try:
64586449
self.FixNoteDurations()
@@ -6486,15 +6477,15 @@ def OnCharEvent(self, evt):
64866477
if (line.rstrip(), caret) == (u'X', 1):
64876478
wx.CallAfter(self.AutoInsertXNum)
64886479

6489-
elif c == '3' and p1 == p2 and self.editor.GetTextRange(p1-1, p1+1) == '()' and is_default_style:
6480+
elif c == '3' and p1 == p2 and self.editor.GetTextRange(p1-1, p1+1) == '()' and in_music_code:
64906481
# if the user writes ( which is auto-completed to () and then writes 3, he/she probably
64916482
# wants to start a triplet so we delete the right parenthesis
64926483
self.editor.BeginUndoAction()
64936484
self.editor.SetSelection(p1, p1+1)
64946485
self.editor.ReplaceSelection(c)
64956486
self.editor.EndUndoAction()
64966487

6497-
elif (c in ']}' and self.editor.GetTextRange(p1, p1+1) == c and is_default_style) or \
6488+
elif (c in ']}' and self.editor.GetTextRange(p1, p1+1) == c and in_music_code) or \
64986489
(c == '"' and self.editor.GetTextRange(p1, p1+1) == c and self.editor.GetTextRange(p1-1, p1) != '\\'):
64996490
(text,pos) = self.editor.GetCurLine()
65006491
# unless this is not a field line
@@ -6537,7 +6528,7 @@ def OnCharEvent(self, evt):
65376528
self.editor.InsertText(p2+1, end)
65386529
self.editor.SetSelection(p1+1, p2+1)
65396530
self.editor.EndUndoAction()
6540-
elif is_default_style and (self.mni_TA_active.IsChecked() and self.mni_TA_add_right.IsChecked()):
6531+
elif in_music_code and use_typing_assist and self.mni_TA_add_right.IsChecked():
65416532
line, _ = self.editor.GetCurLine()
65426533
if c == '"' and line.count('"') % 2 == 1 or \
65436534
c != '"' and line.count(end) > line.count(start):
@@ -6593,7 +6584,7 @@ def OnCharEvent(self, evt):
65936584
self.editor.SetSelection(p1, p2+total_offset)
65946585
finally:
65956586
self.editor.EndUndoAction()
6596-
elif self.keyboard_input_mode and is_default_style:
6587+
elif self.keyboard_input_mode and in_music_code:
65976588
keys = u'asdfghjkl\xf6\xe4'
65986589
sharp_keys = '' #u'\x00wertyuiop\xe5\x00'
65996590
flat_keys = '' #u'<zxcvbnm,.-'
@@ -6615,7 +6606,7 @@ def OnCharEvent(self, evt):
66156606
self.editor.ReplaceSelection(accidental + note)
66166607

66176608
# automatically select uppercase/lowercase - choose the one that will make this note be closest to the previous note
6618-
elif p1 == p2 and at_end_of_line and is_default_style and (self.mni_TA_active.IsChecked() and self.mni_TA_auto_case.IsChecked()) and \
6609+
elif p1 == p2 and at_end_of_line and in_music_code and (use_typing_assist and self.mni_TA_auto_case.IsChecked()) and \
66196610
(not self.mni_TA_do_re_mi.IsChecked() and c in 'abcdefgABCDEFG' or \
66206611
self.mni_TA_do_re_mi.IsChecked() and c in doremi_prefixes):
66216612
last_note_number = None
@@ -6632,10 +6623,10 @@ def OnCharEvent(self, evt):
66326623

66336624
# go backwards (to the left from the cursor) and look for the first note
66346625
for i in range(len(text)-1):
6635-
if p-i >= 1 and self.editor.GetStyleAt(p-i-1) in [self.styler.STYLE_DEFAULT, self.styler.STYLE_GRACE]:
6636-
m = re.match(r"([A-Ga-g])[,']?", text[len(text)-1-i:len(text)-1-i+2])
6626+
if p-i >= 1 and self.position_is_music_code(p-i-1):
6627+
m = re.match(r"([A-Ga-g][,']?)", text[len(text)-1-i : len(text)-1-i+2])
66376628
if m:
6638-
last_note_number = all_notes.index(m.group(0))
6629+
last_note_number = note_to_index(m.group(0))
66396630
break
66406631

66416632
if last_note_number is None:
@@ -6660,7 +6651,7 @@ def OnCharEvent(self, evt):
66606651
else:
66616652
evt.Skip()
66626653

6663-
elif self.mni_TA_active.IsChecked() and self.mni_TA_do_re_mi.IsChecked() and is_default_style:
6654+
elif use_typing_assist and self.mni_TA_do_re_mi.IsChecked() and in_music_code:
66646655
if c in doremi_prefixes:
66656656
c = self.DoReMiToNote(c)
66666657
self.editor.AddText(c)
@@ -6813,6 +6804,9 @@ def replace_selection(self, text):
68136804
self.editor.ReplaceSelection(text)
68146805
self.editor.EndUndoAction()
68156806

6807+
def position_is_music_code(self, position):
6808+
return self.editor.GetStyleAt(position) in [self.styler.STYLE_DEFAULT, self.styler.STYLE_GRACE]
6809+
68166810
def OnKeyDownEvent(self, evt):
68176811
# temporary work-around for what seems to be a scintilla bug on Mac:
68186812
if wx.Platform == "__WXMAC__" and evt.GetRawKeyCode() == 7683:
@@ -6828,13 +6822,13 @@ def OnKeyDownEvent(self, evt):
68286822

68296823
line, caret = self.editor.GetCurLine()
68306824
is_inside_field = len(line)>=2 and line[1] == ':' and re.match(r'[A-Za-z]', line[0]) or line.startswith('%')
6831-
is_default_style = (self.editor.GetStyleAt(self.editor.GetCurrentPos()) in
6832-
[self.styler.STYLE_DEFAULT, self.styler.STYLE_GRACE])
6825+
in_music_code = self.position_is_music_code(self.editor.GetCurrentPos())
68336826

6827+
use_typing_assist = self.mni_TA_active.IsChecked()
68346828
if evt.GetKeyCode() == wx.WXK_RETURN:
68356829
line = self.editor.GetCurrentLine()
68366830
# 1.3.7.2 [JWDJ] 2016-03-17
6837-
if self.mni_TA_active.IsChecked() and self.mni_TA_add_bar_auto.IsChecked() and not is_inside_field and is_default_style:
6831+
if use_typing_assist and self.mni_TA_add_bar_auto.IsChecked() and not is_inside_field and in_music_code:
68386832
self.add_bar_if_needed()
68396833

68406834
# 1.3.6.3 [JWDJ] 2015-04-21 Added line continuation
@@ -6877,7 +6871,7 @@ def StartKeyboardInputMode(self):
68776871
if notes:
68786872
self.keyboard_input_mode = True
68796873
m = re.match(r"([_=^]?)(?P<note>[A-Ga-gz][,']*)", notes[-1][-1])
6880-
self.keyboard_input_base_note = all_notes.index(m.group('note'))
6874+
self.keyboard_input_base_note = note_to_index(m.group('note'))
68816875
self.keyboard_input_base_key = None
68826876
if self.keyboard_input_base_note == -1:
68836877
self.keyboard_input_mode = False
@@ -7374,8 +7368,10 @@ def SetErrorMessage(self, error_msg):
73747368
self.editor.ScrollToLine(self.editor.LineFromPosition(self.editor.GetCurrentPos()))
73757369

73767370
def OnPageSelected(self, evt):
7377-
# 1.3.6.2 [JWdJ] 2015-02
7378-
self.current_page_index = self.cur_page_combo.GetSelection()
7371+
self.select_page(self.cur_page_combo.GetSelection())
7372+
7373+
def select_page(self, page_index):
7374+
self.current_page_index = page_index
73797375
self.UpdateMusicPane()
73807376

73817377
def UpdateMusicPane(self):

‎midiplayer.py

-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
from __future__ import unicode_literals
2-
import re
3-
import os
4-
import io
5-
import os.path
6-
import wx
7-
import wx.media
8-
import time
9-
import sys
10-
PY3 = sys.version_info.major > 2
112

123

134
class EventHook(object):

‎tune_actions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ def key_and_body(self):
15191519
%%MIDI drummap F 35
15201520
V:1
15211521
%%MIDI channel 10
1522-
^a^g[c^g]^g | ^g^g[c^g]_g | ^a^g[c^g]^g | ^g/c/^g c/^a3/ ||
1522+
^a^g[c^g]^g | ^g^g[c^g]_g | ^g^g[c^g]^g | ^g/c/^g c/^a3/ ||
15231523
V:2
15241524
%%MIDI channel 10
15251525
FF/F/ z3/{/F}F/ | zF/F/ z/F3/ | FF/F/ z3/F/ | z3/F/ z/F3/ ||

0 commit comments

Comments
 (0)
Please sign in to comment.