1
1
#
2
2
3
- == == == =
4
3
program_name = 'EasyABC 1.3.7.9 2021-01-01'
5
4
6
5
# Copyright (C) 2011-2014 Nils Liberg (mail: kotorinl at yahoo.co.uk)
@@ -1801,6 +1800,18 @@ def timedelta_microseconds(self, td):
1801
1800
def beat_duration (self ):
1802
1801
return 1000000 * 60 / self .bpm # unit is microseconds
1803
1802
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
+
1804
1815
def run (self ):
1805
1816
self .is_running = True
1806
1817
NOTE_ON = 0x09
@@ -1813,35 +1824,53 @@ def run(self):
1813
1824
time .sleep (0.002 )
1814
1825
try :
1815
1826
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 :
1817
1828
time .sleep (0.00025 )
1818
1829
if self .timedelta_microseconds (datetime .now () - start_time ) / self .beat_duration > i :
1819
1830
last_tick = datetime .now ()
1820
- i += 1
1821
1831
if i % self .metre_1 == 0 :
1822
1832
wx .CallAfter (self .tick1 .Play )
1823
1833
else :
1824
1834
wx .CallAfter (self .tick2 .Play )
1835
+ i += 1 #FAU: 20210102: One tick was missing the first time so incrementing i after the tick
1836
+
1825
1837
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
1828
1843
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 )
1830
1848
cmd = data [0 ][0 ][0 ] >> 4
1831
1849
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 :
1833
1853
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 :
1836
1856
start = float (noteon_time [midi_note ]) / self .beat_duration
1837
1857
end = float (time_offset ) / self .beat_duration
1838
1858
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
+
1840
1861
1841
1862
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 ()
1843
1869
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 ()
1845
1874
self .is_running = False
1846
1875
self .quantize ()
1847
1876
wx .PostEvent (self ._notify_window , RecordStopEvent (- 1 , self .notes ))
@@ -2731,11 +2760,21 @@ def __init__(self, parent, settings):
2731
2760
outputDevices = [_ ('None' )]
2732
2761
outputDeviceIDs = [None ]
2733
2762
if 'pypm' in globals ():
2734
- n = pypm .CountDevices ()
2763
+ if wx .Platform == "__WXMAC__" :
2764
+ n = pypm .get_count ()
2765
+ else :
2766
+ n = pypm .CountDevices ()
2735
2767
else :
2736
2768
n = 0
2737
2769
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 )
2739
2778
if input :
2740
2779
inputDevices .append (name )
2741
2780
inputDeviceIDs .append (i )
@@ -4427,14 +4466,15 @@ def music_and_score_out_of_sync(self):
4427
4466
def OnRecordBpmSelected (self , evt ):
4428
4467
menu = evt .EventObject
4429
4468
item = menu .FindItemById (evt .GetId ())
4430
- self .settings ['record_bpm' ] = int (item .GetText ())
4469
+ self .settings ['record_bpm' ] = int (item .GetItemLabelText ())
4431
4470
if self .record_thread :
4432
4471
self .record_thread .bpm = self .settings ['record_bpm' ]
4433
4472
4434
4473
def OnRecordMetreSelected (self , evt ):
4435
4474
menu = evt .EventObject
4436
4475
item = menu .FindItemById (evt .GetId ())
4437
- self .settings ['record_metre' ] = item .GetText ()
4476
+ self .settings ['record_metre' ] = item .GetItemLabelText ()
4477
+
4438
4478
4439
4479
# 1.3.6.3 [SS] 2015-05-03
4440
4480
def flip_tempobox (self , state ):
0 commit comments