@@ -789,12 +789,11 @@ def cb_midi_in(self, data, timestamp, force_channel=None):
789
789
# rewrite the output channel based on app's MPE settings
790
790
self .midi_write (self .midi_out , data , timestamp )
791
791
else :
792
- # pitch bend
793
792
# rewrite the output channel based on app's MPE settings
794
793
if force_channel :
795
- data [0 ] = (d0 & 0xF0 ) + (force_channel - 1 )
794
+ data [0 ] = (d0 & 0xF0 ) | (force_channel - 1 )
796
795
elif not self .is_mpe ():
797
- data [0 ] = (d0 & 0xF0 ) + (self .options .one_channel - 1 )
796
+ data [0 ] = (d0 & 0xF0 ) | (self .options .one_channel - 1 )
798
797
799
798
skip = False
800
799
if msg == 14 :
@@ -831,6 +830,46 @@ def cb_midi_in(self, data, timestamp, force_channel=None):
831
830
# print('pitch', bend, semitones)
832
831
# stabilized = True
833
832
833
+ # This block has to happen before the below block rewrites y axis to pitch bend
834
+ if self .options .y_bend :
835
+ pb_range = self .options .bend_range * 2
836
+ bend_threshold = 1 # units
837
+ if msg == 14 :
838
+ # if y-bending enabled, rewrite pitch bend based on y bend value
839
+ note = self .notes [ch ]
840
+ # if note.y_bend > EPSILON:
841
+ val = decompose_pitch_bend ((data [1 ], data [2 ]))
842
+ note .bend = val
843
+ val += note .y_bend / pb_range
844
+ data [1 ], data [2 ] = compose_pitch_bend (val )
845
+
846
+ if msg == 11 and data [1 ] == 74 :
847
+ # print(data[2])
848
+ if data [2 ] > 127 - bend_threshold :
849
+ bend = (data [2 ] - (127 - bend_threshold )) / bend_threshold
850
+ elif data [2 ] <= bend_threshold :
851
+ # bend down?
852
+ # bend = -(bend_threshold - data[2]) / bend_threshold
853
+ bend = None
854
+ else :
855
+ bend = None
856
+ note = self .notes [ch ]
857
+ data = [0xe0 | ch ,0 ,0 ]
858
+ if force_channel :
859
+ data [0 ] = 0xe0 | (force_channel - 1 )
860
+ elif not self .is_mpe ():
861
+ data [0 ] = 0xe0 | (self .options .one_channel - 1 )
862
+ if bend is not None :
863
+ if bend > 0.9 :
864
+ bend = 1.0
865
+ elif bend < - 0.9 :
866
+ bend = - 1.0
867
+ note .y_bend = bend
868
+ data [1 ], data [2 ] = compose_pitch_bend (note .bend + note .y_bend / pb_range )
869
+ else :
870
+ note .y_bend = 0.0
871
+ data [1 ], data [2 ] = compose_pitch_bend (note .bend + note .y_bend / pb_range )
872
+
834
873
if skip :
835
874
pass
836
875
elif msg == 11 and data [1 ] == 64 : # sustain pedal
@@ -1127,6 +1166,9 @@ def __init__(self):
1127
1166
self .options .one_channel = get_option (
1128
1167
opts , "one_channel" , DEFAULT_OPTIONS .one_channel
1129
1168
)
1169
+ self .options .bend_range = get_option (
1170
+ opts , "bend_range" , DEFAULT_OPTIONS .bend_range
1171
+ )
1130
1172
1131
1173
if "--lite" in sys .argv :
1132
1174
self .options .lite = True
@@ -1679,8 +1721,8 @@ def mpe_rpn(self, on=True):
1679
1721
1680
1722
def bend_rpn (self , on = True ):
1681
1723
if on :
1682
- self .rpn (19 , 24 )
1683
- self .rpn (119 , 24 )
1724
+ self .rpn (19 , self . options . bend_range )
1725
+ self .rpn (119 , self . options . bend_range )
1684
1726
else :
1685
1727
self .rpn (19 , 48 )
1686
1728
self .rpn (119 , 48 )
0 commit comments