forked from g0orx/linhpsdr
-
Notifications
You must be signed in to change notification settings - Fork 7
/
mic_level.c
157 lines (133 loc) · 5.19 KB
/
mic_level.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
/* Copyright (C)
* 2018 - John Melton, G0ORX/N6LYT
*
* 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 <wdsp.h>
#include "discovered.h"
#include "bpsk.h"
#include "wideband.h"
#include "adc.h"
#include "dac.h"
#include "receiver.h"
#include "transmitter.h"
#include "radio.h"
#include "main.h"
#include "mic_level.h"
#include "vfo.h"
#include "level_meter.h"
static char *title="Microphone Level";
static gboolean mic_level_configure_event_cb(GtkWidget *widget,GdkEventConfigure *event,gpointer data) {
int width=gtk_widget_get_allocated_width (widget);
int height=gtk_widget_get_allocated_height (widget);
if(radio->mic_level_surface) {
cairo_surface_destroy(radio->mic_level_surface);
}
if(radio->mic_level!=NULL) {
radio->mic_level_surface = gdk_window_create_similar_surface (gtk_widget_get_window (radio->mic_level), CAIRO_CONTENT_COLOR, width, height);
cairo_t *cr;
cr = cairo_create (radio->mic_level_surface);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo_paint (cr);
cairo_destroy(cr);
}
return TRUE;
}
static gboolean mic_level_draw_cb(GtkWidget *widget,cairo_t *cr,gpointer data) {
if(radio->mic_level_surface!=NULL) {
cairo_set_source_surface (cr, radio->mic_level_surface, 0.0, 0.0);
cairo_paint (cr);
}
return TRUE;
}
static gboolean mic_level_press_event_cb(GtkWidget *widget,GdkEventButton *event,gpointer data) {
int width=gtk_widget_get_allocated_width(widget);
double x=event->x;
radio->vox_threshold=(x-5.0)/(double)width;
if(radio->vox_threshold<0.0) {
radio->vox_threshold=0.0;
} else if(radio->vox_threshold>1.0) {
radio->vox_threshold=1.0;
}
update_mic_level(radio);
return TRUE;
}
static gboolean mic_level_scroll_event_cb(GtkWidget *widget,GdkEventScroll *event,gpointer data) {
if(event->direction==GDK_SCROLL_UP) {
radio->vox_threshold+=0.01;
} else {
radio->vox_threshold-=0.01;
}
if(radio->vox_threshold<0.0) radio->vox_threshold=0.0;
if(radio->vox_threshold>1.0) radio->vox_threshold=1.0;
update_mic_level(radio);
return TRUE;
}
static gboolean enter (GtkWidget *ebox, GdkEventCrossing *event) {
//gdk_window_set_cursor(gtk_widget_get_window(ebox),gdk_cursor_new(GDK_DOUBLE_ARROW));
gdk_window_set_cursor(gtk_widget_get_window(ebox),gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW));
return FALSE;
}
static gboolean leave (GtkWidget *ebox, GdkEventCrossing *event) {
gdk_window_set_cursor(gtk_widget_get_window(ebox),gdk_cursor_new(GDK_ARROW));
return FALSE;
}
GtkWidget *create_mic_level(TRANSMITTER *tx) {
radio->mic_level_surface=NULL;
radio->mic_level=gtk_drawing_area_new();
//gtk_widget_set_size_request(radio->mic_level, 10, 100);
g_signal_connect(radio->mic_level,"configure-event",G_CALLBACK(mic_level_configure_event_cb),(gpointer)tx);
g_signal_connect(radio->mic_level,"draw",G_CALLBACK(mic_level_draw_cb),(gpointer)tx);
g_signal_connect(radio->mic_level,"enter-notify-event",G_CALLBACK (enter),NULL);
g_signal_connect(radio->mic_level,"leave-notify-event",G_CALLBACK (leave),NULL);
g_signal_connect(radio->mic_level,"button-press-event",G_CALLBACK(mic_level_press_event_cb),(gpointer)tx);
g_signal_connect(radio->mic_level,"scroll_event",G_CALLBACK(mic_level_scroll_event_cb),(gpointer)tx);
gtk_widget_set_events (radio->mic_level, gtk_widget_get_events (radio->mic_level)
| GDK_BUTTON_PRESS_MASK
| GDK_SCROLL_MASK
| GDK_ENTER_NOTIFY_MASK
| GDK_LEAVE_NOTIFY_MASK);
return radio->mic_level;
}
void update_mic_level(RADIO *r) {
int i;
double x;
cairo_text_extents_t extents;
if(r->mic_level_surface!=NULL) {
cairo_t *cr;
cr = cairo_create (r->mic_level_surface);
int width=gtk_widget_get_allocated_width(r->mic_level);
int height=gtk_widget_get_allocated_height(r->mic_level);
int bar_width=width-10;
double peak=radio->vox_peak*(double)bar_width;
level_meter_draw(cr, peak, width, height, INFO_ON);
// Vox threshold marker
SetColour(cr, WARNING);
double threshold=radio->vox_threshold*(double)bar_width;
cairo_move_to(cr,threshold+5.0,1);
cairo_line_to(cr,threshold+5.0,height/2);
cairo_stroke(cr);
SetColour(cr, TEXT_B);
cairo_select_font_face(cr, "Noto Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr,10);
cairo_text_extents(cr, title, &extents);
cairo_move_to(cr,(5+width/2)-(extents.width/2.0),height-2);
cairo_show_text(cr,title);
cairo_destroy(cr);
gtk_widget_queue_draw(r->mic_level);
}
}