Optimize plugin-processing for non-automated params
[ardour.git] / libs / ardour / ardour / value_as_string.h
index 6c17ace5d3baba3f0140ae99e684701ab193a47c..ed257d5cb56767ea1f6fdb84a07e7ab09eaa881b 100644 (file)
 
 #include <stddef.h>
 
+#include "ardour/dB.h"
 #include "ardour/parameter_descriptor.h"
 
+#include "pbd/i18n.h"
+
 namespace ARDOUR {
 
 inline std::string
@@ -44,24 +47,29 @@ value_as_string(const ARDOUR::ParameterDescriptor& desc,
                }
        }
 
+       if (desc.toggled) {
+               return v > 0 ? _("on") : _("off");
+       }
+
        // Value is not a scale point, print it normally
        if (desc.unit == ARDOUR::ParameterDescriptor::MIDI_NOTE) {
-               if (v >= 0 && v <= 127) {
-                       const int         num          = rint(v);
-                       static const char names[12][3] = {
-                               "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"
-                       };
-                       snprintf(buf, sizeof(buf), "%s %d", names[num % 12], (num / 12) - 2);
-               } else {
-                       // Odd, invalid range, just print the number
-                       snprintf(buf, sizeof(buf), "%.0f", v);
-               }
+               snprintf(buf, sizeof(buf), "%s", ParameterDescriptor::midi_note_name (rint(v)).c_str());
+       } else if (desc.type == GainAutomation || desc.type == TrimAutomation || desc.type == EnvelopeAutomation) {
+               snprintf(buf, sizeof(buf), "%.1f dB", accurate_coefficient_to_dB (v));
+       } else if (desc.type == PanWidthAutomation) {
+               snprintf (buf, sizeof (buf), "%d%%", (int) floor (100.0 * v));
+       } else if (!desc.print_fmt.empty()) {
+               snprintf(buf, sizeof(buf), desc.print_fmt.c_str(), v);
        } else if (desc.integer_step) {
                snprintf(buf, sizeof(buf), "%d", (int)v);
-       } else {
+       } else if (desc.upper - desc.lower >= 1000) {
+               snprintf(buf, sizeof(buf), "%.1f", v);
+       } else if (desc.upper - desc.lower >= 100) {
                snprintf(buf, sizeof(buf), "%.2f", v);
+       } else {
+               snprintf(buf, sizeof(buf), "%.3f", v);
        }
-       if (desc.unit == ARDOUR::ParameterDescriptor::DB) {
+       if (desc.print_fmt.empty() && desc.unit == ARDOUR::ParameterDescriptor::DB) {
                // TODO: Move proper dB printing from AutomationLine here
                return std::string(buf) + " dB";
        }