Skip to content

Commit e0387a6

Browse files
authored
Merge pull request #36 from aupfred/midi-recording-mac
Midi recording mac
2 parents 1165e10 + f99e433 commit e0387a6

File tree

2 files changed

+57
-16
lines changed

2 files changed

+57
-16
lines changed

easy_abc.py

+56-15
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,18 @@ def timedelta_microseconds(self, td):
18041804
def beat_duration(self):
18051805
return 1000000 * 60 / self.bpm # unit is microseconds
18061806

1807+
@property
1808+
def midi_in_poll(self):
1809+
if wx.Platform == "__WXMAC__":
1810+
return self.midi_in.poll()
1811+
else:
1812+
return self.midi_in.Poll()
1813+
1814+
def number_to_note(self, number):
1815+
notes = ['c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#', 'a', 'a#', 'b']
1816+
return notes[number%12]
1817+
1818+
18071819
def run(self):
18081820
self.is_running = True
18091821
NOTE_ON = 0x09
@@ -1816,35 +1828,53 @@ def run(self):
18161828
time.sleep(0.002)
18171829
try:
18181830
while not self._want_abort:
1819-
while not self.midi_in.Poll() and not self._want_abort:
1831+
while not self.midi_in_poll and not self._want_abort:
18201832
time.sleep(0.00025)
18211833
if self.timedelta_microseconds(datetime.now() - start_time) / self.beat_duration > i:
18221834
last_tick = datetime.now()
1823-
i += 1
18241835
if i % self.metre_1 == 0:
18251836
wx.CallAfter(self.tick1.Play)
18261837
else:
18271838
wx.CallAfter(self.tick2.Play)
1839+
i += 1 #FAU: 20210102: One tick was missing the first time so incrementing i after the tick
1840+
18281841
time_offset = self.timedelta_microseconds(datetime.now() - start_time)
1829-
if self.midi_in.Poll():
1830-
data = self.midi_in.Read(1) # read only 1 message at a time
1842+
if self.midi_in_poll:
1843+
if wx.Platform == "__WXMAC__":
1844+
data = self.midi_in.read(1)
1845+
else:
1846+
data = self.midi_in.Read(1) # read only 1 message at a time
18311847
if self.midi_out is not None:
1832-
self.midi_out.Write(data)
1848+
if wx.Platform == "__WXMAC__":
1849+
self.midi_out.write(data)
1850+
else:
1851+
self.midi_out.Write(data)
18331852
cmd = data[0][0][0] >> 4
18341853
midi_note = data[0][0][1]
1835-
if cmd == NOTE_ON:
1854+
midi_note_velocity = data[0][0][2]
1855+
#print(self.number_to_note(midi_note), midi_note_velocity)
1856+
if cmd == NOTE_ON and midi_note_velocity > 0:
18361857
noteon_time[midi_note] = time_offset
1837-
##print 'note-on', midi_note, float(time_offset)/beat_duration
1838-
elif cmd == NOTE_OFF and midi_note in noteon_time:
1858+
#print('note-on', midi_note, float(time_offset)/self.beat_duration)
1859+
elif (cmd == NOTE_OFF or midi_note_velocity ==0) and midi_note in noteon_time:
18391860
start = float(noteon_time[midi_note]) / self.beat_duration
18401861
end = float(time_offset) / self.beat_duration
18411862
self.notes.append([midi_note, start, end])
1842-
##print 'note-off', midi_note, float(time_offset)/beat_duration
1863+
#print('note-off', midi_note, float(time_offset)/self.beat_duration)
1864+
18431865

18441866
finally:
1845-
self.midi_in.Close()
1867+
#print('FAU: closing')
1868+
#print(self.notes)
1869+
if wx.Platform == "__WXMAC__":
1870+
self.midi_in.close()
1871+
else:
1872+
self.midi_in.Close()
18461873
if self.midi_out is not None:
1847-
self.midi_out.Close()
1874+
if wx.Platform == "__WXMAC__":
1875+
self.midi_out.close()
1876+
else:
1877+
self.midi_out.Close()
18481878
self.is_running = False
18491879
self.quantize()
18501880
wx.PostEvent(self._notify_window, RecordStopEvent(-1, self.notes))
@@ -2739,11 +2769,21 @@ def __init__(self, parent, settings):
27392769
outputDevices = [_('None')]
27402770
outputDeviceIDs = [None]
27412771
if 'pypm' in globals():
2742-
n = pypm.CountDevices()
2772+
if wx.Platform == "__WXMAC__":
2773+
n = pypm.get_count()
2774+
else:
2775+
n = pypm.CountDevices()
27432776
else:
27442777
n = 0
27452778
for i in range(n):
2746-
interface, name, input, output, opened = pypm.GetDeviceInfo(i)
2779+
if wx.Platform == "__WXMAC__":
2780+
interface, name, input, output, opened = pypm.get_device_info(i)
2781+
try:
2782+
name = str(name,'utf-8')
2783+
except:
2784+
name = str(name,'mac_roman')
2785+
else:
2786+
interface, name, input, output, opened = pypm.GetDeviceInfo(i)
27472787
if input:
27482788
inputDevices.append(name)
27492789
inputDeviceIDs.append(i)
@@ -4473,14 +4513,15 @@ def music_and_score_out_of_sync(self):
44734513
def OnRecordBpmSelected(self, evt):
44744514
menu = evt.EventObject
44754515
item = menu.FindItemById(evt.GetId())
4476-
self.settings['record_bpm'] = int(item.GetText())
4516+
self.settings['record_bpm'] = int(item.GetItemLabelText())
44774517
if self.record_thread:
44784518
self.record_thread.bpm = self.settings['record_bpm']
44794519

44804520
def OnRecordMetreSelected(self, evt):
44814521
menu = evt.EventObject
44824522
item = menu.FindItemById(evt.GetId())
4483-
self.settings['record_metre'] = item.GetText()
4523+
self.settings['record_metre'] = item.GetItemLabelText()
4524+
44844525

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

midi2abc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def note_to_string(note, duration, default_len, key_accidentals, cur_accidentals
183183
if octave >= 1:
184184
n = n.lower()
185185
if octave > 1:
186-
n = n + "'" * (octave - 1)
186+
n = n + "'" * int(octave - 1)
187187
elif octave < 0:
188188
if abs(octave) >= 1:
189189
n = n + "," * abs(octave)

0 commit comments

Comments
 (0)