Skip to content

Commit 645836c

Browse files
committed
Adapting to pygame.midi interface and few bug fix
1 parent 2ec9a60 commit 645836c

File tree

2 files changed

+57
-17
lines changed

2 files changed

+57
-17
lines changed

easy_abc.py

+56-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#
22

3-
=======
43
program_name = 'EasyABC 1.3.7.9 2021-01-01'
54

65
# Copyright (C) 2011-2014 Nils Liberg (mail: kotorinl at yahoo.co.uk)
@@ -1801,6 +1800,18 @@ def timedelta_microseconds(self, td):
18011800
def beat_duration(self):
18021801
return 1000000 * 60 / self.bpm # unit is microseconds
18031802

1803+
@property
1804+
def midi_in_poll(self):
1805+
if wx.Platform == "__WXMAC__":
1806+
return self.midi_in.poll()
1807+
else:
1808+
return self.midi_in.Poll()
1809+
1810+
def number_to_note(self, number):
1811+
notes = ['c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#', 'a', 'a#', 'b']
1812+
return notes[number%12]
1813+
1814+
18041815
def run(self):
18051816
self.is_running = True
18061817
NOTE_ON = 0x09
@@ -1813,35 +1824,53 @@ def run(self):
18131824
time.sleep(0.002)
18141825
try:
18151826
while not self._want_abort:
1816-
while not self.midi_in.Poll() and not self._want_abort:
1827+
while not self.midi_in_poll and not self._want_abort:
18171828
time.sleep(0.00025)
18181829
if self.timedelta_microseconds(datetime.now() - start_time) / self.beat_duration > i:
18191830
last_tick = datetime.now()
1820-
i += 1
18211831
if i % self.metre_1 == 0:
18221832
wx.CallAfter(self.tick1.Play)
18231833
else:
18241834
wx.CallAfter(self.tick2.Play)
1835+
i += 1 #FAU: 20210102: One tick was missing the first time so incrementing i after the tick
1836+
18251837
time_offset = self.timedelta_microseconds(datetime.now() - start_time)
1826-
if self.midi_in.Poll():
1827-
data = self.midi_in.Read(1) # read only 1 message at a time
1838+
if self.midi_in_poll:
1839+
if wx.Platform == "__WXMAC__":
1840+
data = self.midi_in.read(1)
1841+
else:
1842+
data = self.midi_in.Read(1) # read only 1 message at a time
18281843
if self.midi_out is not None:
1829-
self.midi_out.Write(data)
1844+
if wx.Platform == "__WXMAC__":
1845+
self.midi_out.write(data)
1846+
else:
1847+
self.midi_out.Write(data)
18301848
cmd = data[0][0][0] >> 4
18311849
midi_note = data[0][0][1]
1832-
if cmd == NOTE_ON:
1850+
midi_note_velocity = data[0][0][2]
1851+
#print(self.number_to_note(midi_note), midi_note_velocity)
1852+
if cmd == NOTE_ON and midi_note_velocity > 0:
18331853
noteon_time[midi_note] = time_offset
1834-
##print 'note-on', midi_note, float(time_offset)/beat_duration
1835-
elif cmd == NOTE_OFF and midi_note in noteon_time:
1854+
#print('note-on', midi_note, float(time_offset)/self.beat_duration)
1855+
elif (cmd == NOTE_OFF or midi_note_velocity ==0) and midi_note in noteon_time:
18361856
start = float(noteon_time[midi_note]) / self.beat_duration
18371857
end = float(time_offset) / self.beat_duration
18381858
self.notes.append([midi_note, start, end])
1839-
##print 'note-off', midi_note, float(time_offset)/beat_duration
1859+
#print('note-off', midi_note, float(time_offset)/self.beat_duration)
1860+
18401861

18411862
finally:
1842-
self.midi_in.Close()
1863+
#print('FAU: closing')
1864+
#print(self.notes)
1865+
if wx.Platform == "__WXMAC__":
1866+
self.midi_in.close()
1867+
else:
1868+
self.midi_in.Close()
18431869
if self.midi_out is not None:
1844-
self.midi_out.Close()
1870+
if wx.Platform == "__WXMAC__":
1871+
self.midi_out.close()
1872+
else:
1873+
self.midi_out.Close()
18451874
self.is_running = False
18461875
self.quantize()
18471876
wx.PostEvent(self._notify_window, RecordStopEvent(-1, self.notes))
@@ -2731,11 +2760,21 @@ def __init__(self, parent, settings):
27312760
outputDevices = [_('None')]
27322761
outputDeviceIDs = [None]
27332762
if 'pypm' in globals():
2734-
n = pypm.CountDevices()
2763+
if wx.Platform == "__WXMAC__":
2764+
n = pypm.get_count()
2765+
else:
2766+
n = pypm.CountDevices()
27352767
else:
27362768
n = 0
27372769
for i in range(n):
2738-
interface, name, input, output, opened = pypm.GetDeviceInfo(i)
2770+
if wx.Platform == "__WXMAC__":
2771+
interface, name, input, output, opened = pypm.get_device_info(i)
2772+
try:
2773+
name = str(name,'utf-8')
2774+
except:
2775+
name = str(name,'mac_roman')
2776+
else:
2777+
interface, name, input, output, opened = pypm.GetDeviceInfo(i)
27392778
if input:
27402779
inputDevices.append(name)
27412780
inputDeviceIDs.append(i)
@@ -4427,14 +4466,15 @@ def music_and_score_out_of_sync(self):
44274466
def OnRecordBpmSelected(self, evt):
44284467
menu = evt.EventObject
44294468
item = menu.FindItemById(evt.GetId())
4430-
self.settings['record_bpm'] = int(item.GetText())
4469+
self.settings['record_bpm'] = int(item.GetItemLabelText())
44314470
if self.record_thread:
44324471
self.record_thread.bpm = self.settings['record_bpm']
44334472

44344473
def OnRecordMetreSelected(self, evt):
44354474
menu = evt.EventObject
44364475
item = menu.FindItemById(evt.GetId())
4437-
self.settings['record_metre'] = item.GetText()
4476+
self.settings['record_metre'] = item.GetItemLabelText()
4477+
44384478

44394479
# 1.3.6.3 [SS] 2015-05-03
44404480
def flip_tempobox(self, state):

midi2abc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def note_to_string(note, duration, default_len, key_accidentals, cur_accidentals
188188
if octave >= 1:
189189
n = n.lower()
190190
if octave > 1:
191-
n = n + "'" * (octave - 1)
191+
n = n + "'" * int(octave - 1)
192192
elif octave < 0:
193193
if abs(octave) >= 1:
194194
n = n + "," * abs(octave)

0 commit comments

Comments
 (0)