~ubuntu-branches/ubuntu/hoary/jamin/hoary

« back to all changes in this revision

Viewing changes to src/compressor-ui.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Jordens
  • Date: 2004-01-17 12:14:37 UTC
  • Revision ID: james.westby@ubuntu.com-20040117121437-3idr2e2m3k5jnm9n
Tags: upstream-0.8.0
ImportĀ upstreamĀ versionĀ 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2003 Steve Harris
 
3
 *
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation; either version 2 of the License, or
 
7
 *  (at your option) any later version.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU General Public License for more details.
 
13
 *
 
14
 *  $Id: compressor-ui.c,v 1.15 2003/11/21 13:09:39 jdepner Exp $
 
15
 */
 
16
 
 
17
#include <stdio.h>
 
18
#include <gtk/gtk.h>
 
19
#include <math.h>
 
20
 
 
21
#include "process.h"
 
22
#include "support.h"
 
23
#include "main.h"
 
24
#include "compressor-ui.h"
 
25
#include "gtkmeter.h"
 
26
#include "state.h"
 
27
#include "scenes.h"
 
28
 
 
29
#define MUG_CORR_FACT 0.4f /* makeup gain correction factor - dampens the
 
30
                              makeup gain correction to stop it over
 
31
                              correcting */
 
32
 
 
33
gboolean adj_cb(GtkAdjustment *adj, gpointer p);
 
34
void at_changed(int id, float value);
 
35
void re_changed(int id, float value);
 
36
void th_changed(int id, float value);
 
37
void ra_changed(int id, float value);
 
38
void kn_changed(int id, float value);
 
39
void ma_changed(int id, float value);
 
40
 
 
41
void calc_auto_gain(int i);
 
42
void draw_comp_curve (int i);
 
43
 
 
44
static GtkWidget *ma[XO_BANDS];
 
45
static GtkAdjustment *adj_at[XO_BANDS];
 
46
static GtkAdjustment *adj_re[XO_BANDS];
 
47
static GtkAdjustment *adj_th[XO_BANDS];
 
48
static GtkAdjustment *adj_ra[XO_BANDS];
 
49
static GtkAdjustment *adj_kn[XO_BANDS];
 
50
static GtkAdjustment *adj_ma[XO_BANDS];
 
51
static int auto_gain[XO_BANDS];
 
52
 
 
53
static GtkMeter *le_meter[XO_BANDS], *ga_meter[XO_BANDS];
 
54
static GtkAdjustment *le_meter_adj[XO_BANDS], *ga_meter_adj[XO_BANDS];
 
55
 
 
56
#define connect_scale(sym, i, member, state_id) \
 
57
        snprintf(name, 255, "comp_" # sym "_%d", i+1); \
 
58
        scale = lookup_widget(main_window, name); \
 
59
        adj_##sym[i] = gtk_range_get_adjustment(GTK_RANGE(scale)); \
 
60
        s_set_callback(state_id, sym##_changed); \
 
61
        s_set_adjustment(state_id, adj_##sym[i]); \
 
62
        s_set_value(state_id, compressors[i].member, 0); \
 
63
        g_signal_connect(G_OBJECT(adj_##sym[i]), "value-changed", G_CALLBACK(adj_cb), (gpointer)state_id); 
 
64
 
 
65
        //g_signal_connect(G_OBJECT(adj_##sym[i]), "value-changed", G_CALLBACK(sym##_changed), (gpointer)i); 
 
66
        //gtk_adjustment_set_value(adj_##sym[i], compressors[i].member);
 
67
 
 
68
void bind_compressors()
 
69
{
 
70
    GtkWidget *scale;
 
71
    char name[256];
 
72
    int i;
 
73
 
 
74
    for (i=0; i<XO_BANDS; i++) {
 
75
        snprintf(name, 255, "comp_le_%d", i+1);
 
76
        le_meter[i] = GTK_METER(lookup_widget(main_window, name));
 
77
        le_meter_adj[i] = gtk_meter_get_adjustment(le_meter[i]);
 
78
 
 
79
        snprintf(name, 255, "comp_ga_%d", i+1);
 
80
        ga_meter[i] = GTK_METER(lookup_widget(main_window, name));
 
81
        ga_meter_adj[i] = gtk_meter_get_adjustment(ga_meter[i]);
 
82
 
 
83
        connect_scale(at, i, attack, S_COMP_ATTACK(i));
 
84
        connect_scale(re, i, release, S_COMP_RELEASE(i));
 
85
        connect_scale(th, i, threshold, S_COMP_THRESH(i));
 
86
        connect_scale(ra, i, ratio, S_COMP_RATIO(i));
 
87
        connect_scale(kn, i, knee, S_COMP_KNEE(i));
 
88
        connect_scale(ma, i, makeup_gain, S_COMP_MAKEUP(i));
 
89
        ma[i] = scale;
 
90
 
 
91
        auto_gain[i] = 0;
 
92
    }
 
93
}
 
94
 
 
95
gboolean adj_cb(GtkAdjustment *adj, gpointer p)
 
96
{
 
97
    s_set_value_ui((int)p, adj->value);
 
98
 
 
99
    return FALSE;
 
100
}
 
101
 
 
102
void at_changed(int id, float value)
 
103
{
 
104
    compressors[id - S_COMP_ATTACK(0)].attack = value;
 
105
    draw_comp_curve(id - S_COMP_ATTACK(0));
 
106
}
 
107
 
 
108
void re_changed(int id, float value)
 
109
{
 
110
    compressors[id - S_COMP_RELEASE(0)].release = value;
 
111
    draw_comp_curve(id - S_COMP_RELEASE(0));
 
112
}
 
113
 
 
114
void th_changed(int id, float value)
 
115
{
 
116
    int band = id - S_COMP_THRESH(0);
 
117
 
 
118
    compressors[band].threshold = value;
 
119
    if (auto_gain[band]) {
 
120
        calc_auto_gain(band);
 
121
    } else {
 
122
        draw_comp_curve(band);
 
123
    }
 
124
    gtk_meter_set_warn_point(le_meter[band], value);
 
125
}
 
126
 
 
127
void ra_changed(int id, float value)
 
128
{
 
129
    int band = id - S_COMP_RATIO(0);
 
130
 
 
131
    compressors[band].ratio = value;
 
132
    if (auto_gain[band]) {
 
133
        calc_auto_gain(band);
 
134
    } else {
 
135
        draw_comp_curve(band);
 
136
    }
 
137
}
 
138
 
 
139
void kn_changed(int id, float value)
 
140
{
 
141
    compressors[id - S_COMP_KNEE(0)].knee = value * 9.0f + 1.0f;
 
142
    draw_comp_curve(id - S_COMP_KNEE(0));
 
143
}
 
144
 
 
145
void ma_changed(int id, float value)
 
146
{
 
147
    compressors[id - S_COMP_MAKEUP(0)].makeup_gain = value;
 
148
    draw_comp_curve(id - S_COMP_MAKEUP(0));
 
149
}
 
150
 
 
151
void calc_auto_gain(int i)
 
152
{
 
153
    if (adj_ma[i] && adj_th[i] && adj_ra[i]) {
 
154
        s_set_value_no_history(S_COMP_MAKEUP(i), (adj_th[i]->value / adj_ra[i]->value - adj_th[i]->value) * MUG_CORR_FACT);
 
155
        //gtk_adjustment_set_value(adj_ma[i], adj_th[i]->value / adj_ra[i]->value - adj_th[i]->value);
 
156
    }
 
157
}
 
158
 
 
159
void compressor_meters_update()
 
160
{
 
161
    int i;
 
162
 
 
163
    for (i=0; i<XO_BANDS; i++) {
 
164
        gtk_adjustment_set_value(le_meter_adj[i], compressors[i].amplitude);
 
165
        gtk_adjustment_set_value(ga_meter_adj[i], compressors[i].gain_red);
 
166
    }
 
167
}
 
168
 
 
169
void comp_set_auto(int band, int state)
 
170
{
 
171
    auto_gain[band] = state;
 
172
    gtk_widget_set_sensitive(ma[band], !state);
 
173
    if (state) {
 
174
        calc_auto_gain(band);
 
175
    }
 
176
 
 
177
    set_scene_warning_button ();
 
178
}
 
179
 
 
180
comp_settings comp_get_settings(int band)
 
181
{
 
182
    return (compressors[band]);
 
183
}
 
184
 
 
185
/* vi:set ts=8 sts=4 sw=4: */