@@ -1804,6 +1804,18 @@ def timedelta_microseconds(self, td):
1804
1804
def beat_duration (self ):
1805
1805
return 1000000 * 60 / self .bpm # unit is microseconds
1806
1806
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
+
1807
1819
def run (self ):
1808
1820
self .is_running = True
1809
1821
NOTE_ON = 0x09
@@ -1816,35 +1828,53 @@ def run(self):
1816
1828
time .sleep (0.002 )
1817
1829
try :
1818
1830
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 :
1820
1832
time .sleep (0.00025 )
1821
1833
if self .timedelta_microseconds (datetime .now () - start_time ) / self .beat_duration > i :
1822
1834
last_tick = datetime .now ()
1823
- i += 1
1824
1835
if i % self .metre_1 == 0 :
1825
1836
wx .CallAfter (self .tick1 .Play )
1826
1837
else :
1827
1838
wx .CallAfter (self .tick2 .Play )
1839
+ i += 1 #FAU: 20210102: One tick was missing the first time so incrementing i after the tick
1840
+
1828
1841
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
1831
1847
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 )
1833
1852
cmd = data [0 ][0 ][0 ] >> 4
1834
1853
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 :
1836
1857
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 :
1839
1860
start = float (noteon_time [midi_note ]) / self .beat_duration
1840
1861
end = float (time_offset ) / self .beat_duration
1841
1862
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
+
1843
1865
1844
1866
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 ()
1846
1873
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 ()
1848
1878
self .is_running = False
1849
1879
self .quantize ()
1850
1880
wx .PostEvent (self ._notify_window , RecordStopEvent (- 1 , self .notes ))
@@ -2739,11 +2769,21 @@ def __init__(self, parent, settings):
2739
2769
outputDevices = [_ ('None' )]
2740
2770
outputDeviceIDs = [None ]
2741
2771
if 'pypm' in globals ():
2742
- n = pypm .CountDevices ()
2772
+ if wx .Platform == "__WXMAC__" :
2773
+ n = pypm .get_count ()
2774
+ else :
2775
+ n = pypm .CountDevices ()
2743
2776
else :
2744
2777
n = 0
2745
2778
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 )
2747
2787
if input :
2748
2788
inputDevices .append (name )
2749
2789
inputDeviceIDs .append (i )
@@ -4473,14 +4513,15 @@ def music_and_score_out_of_sync(self):
4473
4513
def OnRecordBpmSelected (self , evt ):
4474
4514
menu = evt .EventObject
4475
4515
item = menu .FindItemById (evt .GetId ())
4476
- self .settings ['record_bpm' ] = int (item .GetText ())
4516
+ self .settings ['record_bpm' ] = int (item .GetItemLabelText ())
4477
4517
if self .record_thread :
4478
4518
self .record_thread .bpm = self .settings ['record_bpm' ]
4479
4519
4480
4520
def OnRecordMetreSelected (self , evt ):
4481
4521
menu = evt .EventObject
4482
4522
item = menu .FindItemById (evt .GetId ())
4483
- self .settings ['record_metre' ] = item .GetText ()
4523
+ self .settings ['record_metre' ] = item .GetItemLabelText ()
4524
+
4484
4525
4485
4526
# 1.3.6.3 [SS] 2015-05-03
4486
4527
def flip_tempobox (self , state ):
0 commit comments