forked from g0orx/pihpsdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_menu.c
250 lines (210 loc) · 8.09 KB
/
filter_menu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>
#include "new_menu.h"
#include "filter_menu.h"
#include "band.h"
#include "bandstack.h"
#include "filter.h"
#include "mode.h"
#include "radio.h"
#include "receiver.h"
#include "vfo.h"
#include "button_text.h"
static GtkWidget *parent_window=NULL;
static GtkWidget *dialog=NULL;
static GtkWidget *last_filter;
static gboolean close_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
if(dialog!=NULL) {
gtk_widget_destroy(dialog);
dialog=NULL;
sub_menu=NULL;
}
return TRUE;
}
int filter_select(void *data) {
int f=(int)data;
vfo_filter_changed(f);
return 0;
}
static gboolean filter_select_cb (GtkWidget *widget, gpointer data) {
filter_select(data);
set_button_text_color(last_filter,"black");
last_filter=widget;
set_button_text_color(last_filter,"orange");
}
static gboolean deviation_select_cb (GtkWidget *widget, gpointer data) {
deviation=(int)data;
if(deviation==2500) {
//setFilter(-4000,4000);
set_filter(active_receiver,-4000,4000);
} else {
//setFilter(-8000,8000);
set_filter(active_receiver,-8000,8000);
}
set_deviation(active_receiver,(double)deviation);
set_button_text_color(last_filter,"black");
last_filter=widget;
set_button_text_color(last_filter,"orange");
vfo_update(NULL);
}
static void var_spin_low_cb (GtkWidget *widget, gpointer data) {
int f=(int)data;
int id=active_receiver->id;
FILTER *mode_filters=filters[vfo[id].mode];
FILTER *filter=&mode_filters[f];
filter->low=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
if(vfo[id].mode==modeCWL || vfo[id].mode==modeCWU) {
filter->high=filter->low;
}
if(f==vfo[id].filter) {
receiver_filter_changed(receiver[id]);
}
}
static void var_spin_high_cb (GtkWidget *widget, gpointer data) {
int f=(int)data;
int id=active_receiver->id;
FILTER *mode_filters=filters[vfo[id].mode];
FILTER *filter=&mode_filters[f];
filter->high=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
if(f==vfo[id].filter) {
receiver_filter_changed(receiver[id]);
}
}
void filter_menu(GtkWidget *parent) {
GtkWidget *b;
int i;
parent_window=parent;
dialog=gtk_dialog_new();
gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parent_window));
gtk_window_set_decorated(GTK_WINDOW(dialog),FALSE);
#ifdef FORCE_WHITE_MENU
GdkRGBA color;
color.red = 1.0;
color.green = 1.0;
color.blue = 1.0;
color.alpha = 1.0;
gtk_widget_override_background_color(dialog,GTK_STATE_FLAG_NORMAL,&color);
#endif
GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(dialog));
GtkWidget *grid=gtk_grid_new();
gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE);
gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE);
gtk_grid_set_column_spacing (GTK_GRID(grid),5);
gtk_grid_set_row_spacing (GTK_GRID(grid),5);
GtkWidget *close_b=gtk_button_new_with_label("Close Filter");
g_signal_connect (close_b, "pressed", G_CALLBACK(close_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),close_b,0,0,1,1);
char label[32];
sprintf(label,"RX %d VFO %s",active_receiver->id,active_receiver->id==0?"A":"B");
GtkWidget *rx_label=gtk_label_new(label);
gtk_grid_attach(GTK_GRID(grid),rx_label,1,0,1,1);
BAND *band=band_get_band(vfo[active_receiver->id].band);
BANDSTACK *bandstack=band->bandstack;
BANDSTACK_ENTRY *entry=&bandstack->entry[vfo[active_receiver->id].bandstack];
FILTER* band_filters=filters[vfo[active_receiver->id].mode];
FILTER* band_filter=&band_filters[vfo[active_receiver->id].filter];
switch(entry->mode) {
case modeFMN:
{
GtkWidget *l=gtk_label_new("Deviation:");
gtk_grid_attach(GTK_GRID(grid),l,0,1,1,1);
GtkWidget *b=gtk_button_new_with_label("2.5K");
if(deviation==2500) {
set_button_text_color(b,"orange");
last_filter=b;
} else {
set_button_text_color(b,"black");
}
g_signal_connect(b,"pressed",G_CALLBACK(deviation_select_cb),(gpointer *)2500);
gtk_grid_attach(GTK_GRID(grid),b,1,1,1,1);
b=gtk_button_new_with_label("5.0K");
if(deviation==5000) {
set_button_text_color(b,"orange");
last_filter=b;
} else {
set_button_text_color(b,"black");
}
g_signal_connect(b,"pressed",G_CALLBACK(deviation_select_cb),(gpointer *)5000);
gtk_grid_attach(GTK_GRID(grid),b,2,1,1,1);
}
break;
default:
for(i=0;i<FILTERS-2;i++) {
FILTER* band_filter=&band_filters[i];
GtkWidget *b=gtk_button_new_with_label(band_filters[i].title);
if(i==vfo[active_receiver->id].filter) {
set_button_text_color(b,"orange");
last_filter=b;
} else {
set_button_text_color(b,"black");
}
gtk_grid_attach(GTK_GRID(grid),b,i%5,1+(i/5),1,1);
g_signal_connect(b,"pressed",G_CALLBACK(filter_select_cb),(gpointer *)i);
}
// last 2 are var1 and var2
int row=1+((i+4)/5);
FILTER* band_filter=&band_filters[i];
GtkWidget *b=gtk_button_new_with_label(band_filters[i].title);
if(i==vfo[active_receiver->id].filter) {
set_button_text_color(b,"orange");
last_filter=b;
} else {
set_button_text_color(b,"black");
}
gtk_grid_attach(GTK_GRID(grid),b,0,row,1,1);
g_signal_connect(b,"pressed",G_CALLBACK(filter_select_cb),(gpointer *)i);
GtkWidget *var1_spin_low=gtk_spin_button_new_with_range(-8000.0,+8000.0,1.0);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(var1_spin_low),(double)band_filter->low);
gtk_grid_attach(GTK_GRID(grid),var1_spin_low,1,row,1,1);
g_signal_connect(var1_spin_low,"value-changed",G_CALLBACK(var_spin_low_cb),(gpointer *)i);
if(vfo[active_receiver->id].mode!=modeCWL && vfo[active_receiver->id].mode!=modeCWU) {
GtkWidget *var1_spin_high=gtk_spin_button_new_with_range(-8000.0,+8000.0,1.0);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(var1_spin_high),(double)band_filter->high);
gtk_grid_attach(GTK_GRID(grid),var1_spin_high,2,row,1,1);
g_signal_connect(var1_spin_high,"value-changed",G_CALLBACK(var_spin_high_cb),(gpointer *)i);
}
row++;
i++;
band_filter=&band_filters[i];
b=gtk_button_new_with_label(band_filters[i].title);
if(i==vfo[active_receiver->id].filter) {
set_button_text_color(b,"orange");
last_filter=b;
} else {
set_button_text_color(b,"black");
}
gtk_grid_attach(GTK_GRID(grid),b,0,row,1,1);
g_signal_connect(b,"pressed",G_CALLBACK(filter_select_cb),(gpointer *)i);
GtkWidget *var2_spin_low=gtk_spin_button_new_with_range(-8000.0,+8000.0,1.0);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(var2_spin_low),(double)band_filter->low);
gtk_grid_attach(GTK_GRID(grid),var2_spin_low,1,row,1,1);
g_signal_connect(var2_spin_low,"value-changed",G_CALLBACK(var_spin_low_cb),(gpointer *)i);
if(vfo[active_receiver->id].mode!=modeCWL && vfo[active_receiver->id].mode!=modeCWU) {
GtkWidget *var2_spin_high=gtk_spin_button_new_with_range(-8000.0,+8000.0,1.0);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(var2_spin_high),(double)band_filter->high);
gtk_grid_attach(GTK_GRID(grid),var2_spin_high,2,row,1,1);
g_signal_connect(var2_spin_high,"value-changed",G_CALLBACK(var_spin_high_cb),(gpointer *)i);
}
break;
}
gtk_container_add(GTK_CONTAINER(content),grid);
sub_menu=dialog;
gtk_widget_show_all(dialog);
}