1 /* FluidSynth - A Software Synthesizer
3 * Copyright (C) 2003 Peter Hanappe and others.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public License
7 * as published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include "fluid_tuning.h"
23 #include "fluidsynth_priv.h"
24 #include "fluid_sys.h"
27 fluid_tuning_t* new_fluid_tuning(const char* name, int bank, int prog)
29 fluid_tuning_t* tuning;
32 tuning = FLUID_NEW(fluid_tuning_t);
34 FLUID_LOG(FLUID_PANIC, "Out of memory");
41 tuning->name = FLUID_STRDUP(name);
47 for (i = 0; i < 128; i++) {
48 tuning->pitch[i] = i * 100.0;
51 tuning->refcount = 1; /* Start with a refcount of 1 */
56 /* Duplicate a tuning */
58 fluid_tuning_duplicate (fluid_tuning_t *tuning)
60 fluid_tuning_t *new_tuning;
63 new_tuning = FLUID_NEW (fluid_tuning_t);
66 FLUID_LOG (FLUID_PANIC, "Out of memory");
72 new_tuning->name = FLUID_STRDUP (tuning->name);
74 if (!new_tuning->name)
76 FLUID_FREE (new_tuning);
77 FLUID_LOG (FLUID_PANIC, "Out of memory");
81 else new_tuning->name = NULL;
83 new_tuning->bank = tuning->bank;
84 new_tuning->prog = tuning->prog;
86 for (i = 0; i < 128; i++)
87 new_tuning->pitch[i] = tuning->pitch[i];
89 new_tuning->refcount = 1; /* Start with a refcount of 1 */
95 delete_fluid_tuning (fluid_tuning_t *tuning)
97 if (tuning->name) FLUID_FREE (tuning->name);
101 /* Add a reference to a tuning object */
103 fluid_tuning_ref (fluid_tuning_t *tuning)
105 fluid_return_if_fail (tuning != NULL);
107 fluid_atomic_int_inc (&tuning->refcount);
110 /* Unref a tuning object, when it reaches 0 it is deleted, returns TRUE if deleted */
112 fluid_tuning_unref (fluid_tuning_t *tuning, int count)
114 fluid_return_val_if_fail (tuning != NULL, FALSE);
116 /* Add and compare are separate, but that is OK, since refcount will only
117 * reach 0 when there are no references and therefore no possibility of
118 * another thread adding a reference in between */
119 fluid_atomic_int_add (&tuning->refcount, -count);
121 /* Delete when refcount reaches 0 */
122 if (!fluid_atomic_int_get (&tuning->refcount))
124 delete_fluid_tuning (tuning);
130 void fluid_tuning_set_name(fluid_tuning_t* tuning, char* name)
132 if (tuning->name != NULL) {
133 FLUID_FREE(tuning->name);
137 tuning->name = FLUID_STRDUP(name);
141 char* fluid_tuning_get_name(fluid_tuning_t* tuning)
146 static void fluid_tuning_set_key(fluid_tuning_t* tuning, int key, double pitch)
148 tuning->pitch[key] = pitch;
151 void fluid_tuning_set_octave(fluid_tuning_t* tuning, const double* pitch_deriv)
155 for (i = 0; i < 128; i++) {
156 tuning->pitch[i] = i * 100.0 + pitch_deriv[i % 12];
160 void fluid_tuning_set_all(fluid_tuning_t* tuning, const double* pitch)
164 for (i = 0; i < 128; i++) {
165 tuning->pitch[i] = pitch[i];
169 void fluid_tuning_set_pitch(fluid_tuning_t* tuning, int key, double pitch)
171 if ((key >= 0) && (key < 128)) {
172 tuning->pitch[key] = pitch;