zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

DSSIControl.h (1954B)


      1 /*
      2   ZynAddSubFX - a software synthesizer
      3 
      4   DSSIControl.h - DSSI control ports "controller"
      5   Copyright (C) 2015 Olivier Jolly
      6   Author: Olivier Jolly
      7 
      8   This program is free software; you can redistribute it and/or
      9   modify it under the terms of the GNU General Public License
     10   as published by the Free Software Foundation; either version 2
     11   of the License, or (at your option) any later version.
     12 */
     13 
     14 #ifndef ZYNADDSUBFX_DSSICONTROL_H
     15 #define ZYNADDSUBFX_DSSICONTROL_H
     16 
     17 
     18 #include "DSSIControlDescription.h"
     19 
     20 struct DSSIControl {
     21 
     22     DSSIControlDescription description;
     23 
     24     float *data; /// pointer to the value for this controller which is updated by the DSSI host
     25 
     26     /**
     27      * Ctr for a DSSIControl based on a DSSIControl description
     28      * @param controller_code the controller code
     29      * @param name the human readable code name
     30      */
     31     DSSIControl(DSSIControlDescription description) : description(description) { }
     32 
     33     /**
     34      * update the current control to the Master in charge of dispatching them to the parts, effects, ...
     35      * @param master the controller master in charge of further dispatch
     36      */
     37     void forward_control(zyn::Master *master);
     38 
     39     /**
     40      * scale the incoming value refereced by data in the hinted range to one expected by the Master dispatcher.
     41      * Boolean are toggled to 0 or 127, ...
     42      */
     43     int get_scaled_data() {
     44         if (LADSPA_IS_HINT_TOGGLED(description.port_range_hint.HintDescriptor)) {
     45             return *data <= 0 ? 0 : 127;
     46         } else if (description.port_range_hint.UpperBound < 127) {
     47             // when not using 127 or 128 as upper bound, scale the input using the port range hint to 0 .. 128
     48             return 128 * (*data - description.port_range_hint.LowerBound) /
     49                    (description.port_range_hint.UpperBound - description.port_range_hint.LowerBound);
     50         } else {
     51             return *data;
     52         }
     53     }
     54 
     55 };
     56 
     57 #endif //ZYNADDSUBFX_DSSICONTROL_H