Frequency change by a mouse wheel

upup

Now you can change the frequency by your mouse wheel. So almost all is done except for the artistic elaboration.

static gboolean cb_mouse_event(GtkWidget *widget, GdkEventScroll *event, gpointer data) { 
    double ifreq_delta;
    int index;
    index = ( 636 - (int) event->x ) / 28; 
    if(index < 0) index = 0;
    if(index > 7) index = 7;
    ifreq_delta = pow(10.0, (double) index); 
    if( (event->direction) == 0 ) {
        ifreq_in_hz += ifreq_delta;
    } else {
        ifreq_in_hz -= ifreq_delta;
    }
    set_freq(ifreq_in_hz);
    return FALSE;
}

The code needs some technical elaboration in converting mouse location to the incremental value of the frequency.

/* main */
    gtk_widget_add_events(drawing_area, GDK_SCROLL_MASK);
    g_signal_connect(G_OBJECT (drawing_area), "scroll-event", G_CALLBACK (cb_mouse_event), NULL);

Leave a Reply

Your email address will not be published. Required fields are marked *