Vuo  2.0.0
VuoTempoRange.c
Go to the documentation of this file.
1 
10 #include "type.h"
11 #include "VuoTempoRange.h"
12 #include "VuoList_VuoTempoRange.h"
13 
15 #ifdef VUO_COMPILER
17  "title" : "Tempo Range",
18  "description" : "A range of BPM values.",
19  "keywords" : [ ],
20  "version" : "1.0.0",
21  "dependencies" : [
22  "VuoList_VuoTempoRange"
23  ]
24  });
25 #endif
26 
36 {
37  const char *valueAsString = "";
38  if (json_object_get_type(js) == json_type_string)
39  valueAsString = json_object_get_string(js);
40 
41  VuoTempoRange value = VuoTempoRange_Andante;
42 
43  if (strcmp(valueAsString, "moderato") == 0)
44  value = VuoTempoRange_Moderato;
45  else if (strcmp(valueAsString, "allegro") == 0)
46  value = VuoTempoRange_Allegro;
47  else if (strcmp(valueAsString, "presto") == 0)
48  value = VuoTempoRange_Presto;
49  else if (strcmp(valueAsString, "prestissimo") == 0)
50  value = VuoTempoRange_Prestissimo;
51 
52  return value;
53 }
54 
59 {
60  char *valueAsString = "andante";
61 
62  if (value == VuoTempoRange_Moderato)
63  valueAsString = "moderato";
64  else if (value == VuoTempoRange_Allegro)
65  valueAsString = "allegro";
66  else if (value == VuoTempoRange_Presto)
67  valueAsString = "presto";
68  else if (value == VuoTempoRange_Prestissimo)
69  valueAsString = "prestissimo";
70 
71  return json_object_new_string(valueAsString);
72 }
73 
78 {
80  VuoListAppendValue_VuoTempoRange(l, VuoTempoRange_Andante);
81  VuoListAppendValue_VuoTempoRange(l, VuoTempoRange_Moderato);
82  VuoListAppendValue_VuoTempoRange(l, VuoTempoRange_Allegro);
83  VuoListAppendValue_VuoTempoRange(l, VuoTempoRange_Presto);
84  VuoListAppendValue_VuoTempoRange(l, VuoTempoRange_Prestissimo);
85  return l;
86 }
87 
92 {
93  // Each BPM range actually covers N to 2N BPM, but only works well for the middle ~60% of the range.
94 
95  char *valueAsString = " 70–110 BPM"; // actually 60–120 BPM
96  // FIGURE SPACE U+2007, to match the width of the numeral
97 
98  if (value == VuoTempoRange_Moderato)
99  valueAsString = "100–140 BPM"; // actually 80-160 BPM
100  else if (value == VuoTempoRange_Allegro)
101  valueAsString = "120–180 BPM"; // actually 100–200 BPM
102  else if (value == VuoTempoRange_Presto)
103  valueAsString = "170–250 BPM"; // actually 140-280 BPM
104  else if (value == VuoTempoRange_Prestissimo)
105  valueAsString = "220–320 BPM"; // actually 180-360 BPM
106 
107  return strdup(valueAsString);
108 }
109 
115 {
116  if (value == VuoTempoRange_Andante)
117  return 60;
118  else if (value == VuoTempoRange_Allegro)
119  return 100;
120  else if (value == VuoTempoRange_Presto)
121  return 140;
122  else if (value == VuoTempoRange_Prestissimo)
123  return 180;
124  else
125  return 80;
126 }
127 
131 bool VuoTempoRange_areEqual(const VuoTempoRange valueA, const VuoTempoRange valueB)
132 {
133  return valueA == valueB;
134 }
135 
139 bool VuoTempoRange_isLessThan(const VuoTempoRange valueA, const VuoTempoRange valueB)
140 {
141  return valueA < valueB;
142 }