@@ -189,40 +189,51 @@ func applyTransformations() {
189189 // convert steps in linear curves from strings (with plain numbers or percent values) to floats between 0 and 255
190190 for _ , curve := range CurrentConfig .Curves {
191191 if curve .Linear != nil && len (curve .Linear .InSteps ) > 0 {
192- curve .Linear .Steps = make (map [int ]float64 )
193-
194- for temp , origstr := range curve .Linear .InSteps {
195- str := strings .TrimSpace (origstr )
196- l := len (str )
197- isPercent := false
198- if l > 1 && str [l - 1 ] == '%' {
199- isPercent = true
200- str = str [:l - 1 ] // cut off '%' because ParseFloat() wouldn't like it
192+ transformCurveSteps (& curve .ID , & curve .Linear .Steps , & curve .Linear .InSteps )
193+ }
194+ if curve .Staircase != nil {
195+ if len (curve .Staircase .InSteps ) > 0 {
196+ transformCurveSteps (& curve .ID , & curve .Staircase .Steps , & curve .Staircase .InSteps )
197+ } else {
198+ ui .Fatal ("Missing steps in curve %s" , curve .ID )
199+ }
200+ }
201+ }
202+ }
203+
204+ func transformCurveSteps (ID * string , Steps * map [int ]float64 , InSteps * map [int ]string ) {
205+ * Steps = make (map [int ]float64 )
206+
207+ for temp , origstr := range * InSteps {
208+ str := strings .TrimSpace (origstr )
209+ l := len (str )
210+ isPercent := false
211+ if l > 1 && str [l - 1 ] == '%' {
212+ isPercent = true
213+ str = str [:l - 1 ] // cut off '%' because ParseFloat() wouldn't like it
214+ }
215+ speed , err := strconv .ParseFloat (str , 64 )
216+ if err != nil {
217+ ui .Fatal ("Invalid curve step value '%s' in %s - must be either just a number or a number followed by '%%'" , origstr , * ID )
218+ } else {
219+ if isPercent {
220+ if speed < 0 || speed > 100 {
221+ ui .Fatal ("invalid curve step value '%s' (=> %f) in %s - must be between 0%% and 100%%" , origstr , speed , * ID )
201222 }
202- speed , err := strconv .ParseFloat (str , 64 )
203- if err != nil {
204- ui .Fatal ("Invalid curve step value '%s' in %s - must be either just a number or a number followed by '%%'" , origstr , curve .ID )
223+ // convert 0-100% into [0..255]
224+ if speed < 1 {
225+ // less than 1% always turns into 0
226+ speed = 0
205227 } else {
206- if isPercent {
207- if speed < 0 || speed > 100 {
208- ui .Fatal ("invalid curve step value '%s' (=> %f) in %s - must be between 0%% and 100%%" , origstr , speed , curve .ID )
209- }
210- // convert 0-100% into [0..255]
211- if speed < 1 {
212- // less than 1% always turns into 0
213- speed = 0
214- } else {
215- // 1% turns into 1, 100% turns into 255
216- // => convert 1..100% to 1..255
217- // => 0..99 to 0..254 and then add 1
218- speed = (speed - 1 )* (254.0 / 99.0 ) + 1
219- }
220- } else if speed < 0 || speed > 255 {
221- ui .Fatal ("invalid curve step value '%s' in %s - must be between 0 and 255" , origstr , curve .ID )
222- }
223- curve .Linear .Steps [temp ] = speed
228+ // 1% turns into 1, 100% turns into 255
229+ // => convert 1..100% to 1..255
230+ // => 0..99 to 0..254 and then add 1
231+ speed = (speed - 1 )* (254.0 / 99.0 ) + 1
224232 }
233+ } else if speed < 0 || speed > 255 {
234+ ui .Fatal ("invalid curve step value '%s' in %s - must be between 0 and 255" , origstr , * ID )
225235 }
236+ (* Steps )[temp ] = speed
226237 }
227238 }
228239}
0 commit comments