@@ -133,15 +133,45 @@ void doSynthCommands() {
133
133
} else if (target == 2 ) {
134
134
instrument_settings -> output_channel = value ;
135
135
} else if (target == 3 ) {
136
- instrument_settings -> p0 = value ;
136
+ if (instrument_settings -> next_type != instrument_settings -> type ) {
137
+ // note : parameters may be refreshed during instrument switch, so should be only updated when the type really switch later on
138
+ instrument_settings -> next_p0 = value ;
139
+ } else {
140
+ instrument_settings -> p0 = value ;
141
+ instrument_settings -> next_p0 = value ;
142
+ }
137
143
} else if (target == 4 ) {
138
- instrument_settings -> p1 = value ;
144
+ if (instrument_settings -> next_type != instrument_settings -> type ) {
145
+ // note : parameters may be refreshed during instrument switch, so should be only updated when the type really switch later on
146
+ instrument_settings -> next_p1 = value ;
147
+ } else {
148
+ instrument_settings -> p1 = value ;
149
+ instrument_settings -> next_p1 ;
150
+ }
139
151
} else if (target == 5 ) {
140
- instrument_settings -> p2 = value ;
152
+ if (instrument_settings -> next_type != instrument_settings -> type ) {
153
+ // note : parameters may be refreshed during instrument switch, so should be only updated when the type really switch later on
154
+ instrument_settings -> next_p2 = value ;
155
+ } else {
156
+ instrument_settings -> p2 = value ;
157
+ instrument_settings -> next_p2 ;
158
+ }
141
159
} else if (target == 6 ) {
142
- instrument_settings -> p3 = value ;
160
+ if (instrument_settings -> next_type != instrument_settings -> type ) {
161
+ // note : parameters may be refreshed during instrument switch, so should be only updated when the type really switch later on
162
+ instrument_settings -> next_p3 = value ;
163
+ } else {
164
+ instrument_settings -> p3 = value ;
165
+ instrument_settings -> next_p3 ;
166
+ }
143
167
} else if (target == 7 ) {
144
- instrument_settings -> p4 = value ;
168
+ if (instrument_settings -> next_type != instrument_settings -> type ) {
169
+ // note : parameters may be refreshed during instrument switch, so should be only updated when the type really switch later on
170
+ instrument_settings -> next_p4 = value ;
171
+ } else {
172
+ instrument_settings -> p4 = value ;
173
+ instrument_settings -> next_p4 ;
174
+ }
145
175
}
146
176
} else {
147
177
#ifdef DEBUG
@@ -1652,39 +1682,25 @@ static int audioCallback(float **inputBuffer, float **outputBuffer, unsigned lon
1652
1682
struct _synth_instrument * instrument = & curr_synth .instruments [k ];
1653
1683
struct _synth_instrument_states * instrument_states = & fas_instrument_states [k ];
1654
1684
1655
- // instrument switch
1685
+ // smooth processing of instrument type
1656
1686
if (instrument_states -> state == 1 ) {
1657
1687
// old instrument faded off, switch to the new one
1658
1688
instrument -> type = instrument -> next_type ;
1689
+ instrument -> p0 = instrument -> next_p0 ;
1690
+ instrument -> p1 = instrument -> next_p1 ;
1691
+ instrument -> p2 = instrument -> next_p2 ;
1692
+ instrument -> p3 = instrument -> next_p3 ;
1693
+ instrument -> p4 = instrument -> next_p4 ;
1659
1694
1660
1695
instrument_states -> state = 0 ;
1661
1696
1662
1697
// override current notes data to smoothly switch on and force an instrument note on trigger (to initialize the newly assigned instrument)
1663
- for (j = s ; j < e ; j += 1 ) {
1664
- struct note * n = & curr_notes [j ];
1665
-
1666
- // override current notes data
1667
- n -> previous_volume_l = 0 ;
1668
- n -> previous_volume_r = 0 ;
1669
-
1670
- n -> diff_volume_l = - n -> previous_volume_l ;
1671
- n -> diff_volume_r = - n -> previous_volume_r ;
1672
- }
1698
+ notesOn (curr_notes , s , e );
1673
1699
}
1674
1700
1675
1701
if (instrument -> type != instrument -> next_type ) {
1676
- // let the actual instrument fade off (smooth transition)
1677
- for (j = s ; j < e ; j += 1 ) {
1678
- struct note * n = & curr_notes [j ];
1679
-
1680
- // override current notes data
1681
- n -> volume_l = 0 ;
1682
- n -> volume_r = 0 ;
1683
-
1684
- n -> diff_volume_l = - n -> previous_volume_l ;
1685
- n -> diff_volume_r = - n -> previous_volume_r ;
1686
- }
1687
-
1702
+ // let the actual instrument fade off (smooth transition) by inserting note off values
1703
+ notesOff (curr_notes , s , e );
1688
1704
// indicate a transition state
1689
1705
instrument_states -> state = 1 ;
1690
1706
}
0 commit comments