need help with callback



        i hope you can help me get the largest function to print 
        [via fprintf() --to a voiceconfile file-- the 

        1) gender [M or F]
        2) pitch
        3) speed [of speech in words/minute]
        4) volume [0 -- 200%]
        5) delay [in 10th of a sec between words


        originalyy, i thought coding this would be trivial.  it may
        well be, but if so, i haven't figured it out!

        this code will be on my options dropdown.  please see
        http://www.thought.org/vbc for my latest pix.  --this is
        entirely raw and unpolished; there are no links besides my
        .signature.

        the reason i am asking help is that my shoulder is giving
        out  and i don't want to press my luck.  also because i am
        still hard in Learn mode with gtk ... so this is one for you
        gurus.

        thanks for insights.. 

        appended: dDemo.



=======

/* from here:: Options callback */
#include <gtk/gtk.h>
#include <string.h>


enum 
{ 
  MALE, 
  FEMALE 
};

  /* globals */
  GtkWidget *gender_radio_male;
  GtkWidget *gender_radio_female;
  GtkWidget *pitch_scale1;
  GtkWidget *speedWPM_scale2;
  GtkWidget *volume_scale3;
  GtkWidget *delay_scale4;
  int valueGender, tgen = 0, tpit = 0, tspe = 0, tvol = 0, tdel =0;;
  double valuePitch, valueSpeed, valueVolume, valueDelay;
  /* end globals */


static void
cb_gender_toggled (GtkToggleButton *button, gpointer userdata)
{

puts("within callback");

  int malefemale = (int)userdata;

  if (gtk_toggle_button_get_active (button))
    {
        if (malefemale == MALE)
           {
                fprintf(stdout, "MALE [7]\n");
           }
        else if (malefemale == FEMALE)
           {
                fprintf(stdout, "FEMALE  [13]\n");
           }
    }
    valueGender = malefemale;
}

static void hscale_value_changed_pitch (GtkRange *hscale, GtkWindow *parentWindow)
{
    //fprintf(stderr,"hscale pitch value: %g\n",value);
}

static void hscale_value_changed_speed (GtkRange *hscale, GtkWindow *parentWindow)
{
    valueSpeed = gtk_range_get_value(hscale);
    //fprintf(stderr,"hscale speed value: %g\n",value);
}

static void hscale_value_changed_volume (GtkRange *hscale, GtkWindow *parentWindow)
{
    valueVolume = gtk_range_get_value(hscale);
    //fprintf(stderr,"hscale volume value: %g\n",value);
}
static void hscale_value_changed_delay (GtkRange *hscale, GtkWindow *parentWindow)
{
    valueDelay = gtk_range_get_value(hscale);
    //fprintf(stderr,"hscale delay value: %g\n",value);
}

int
main (int argc, char *argv[])
{
  /*
   * Declare the GTK Widgets used in the program
   */
  GtkWidget *dialog;
  GtkWidget *main_hbox;   //hbox1

  GtkWidget *gender_frame;
  GtkWidget *gender_align;
  GtkWidget *gender_hbox;  // hbox2
  /*
  GtkWidget *gender_radio_male;
  GtkWidget *gender_radio_female;
   */

  GtkWidget *params_frame;
  GtkWidget *params_align;

  GtkWidget *params_table;

  GtkWidget *temp_widget;
  GtkWidget *parent_window;

  /*
     Initialize GTK
   */
  gtk_init (&argc, &argv);


  parent_window = NULL; //Set to parent window if you want the dialog box
                        //to block access to the other windows in the app
                        //while it is open and running.


  dialog = gtk_dialog_new_with_buttons ("Voice Settings", GTK_WINDOW (parent_window), 
    0, 
    GTK_STOCK_REVERT_TO_SAVED,  //revert button which
    GTK_RESPONSE_CANCEL,        //  returns a cancel response
    GTK_STOCK_CLOSE,            //close button which
    GTK_RESPONSE_ACCEPT,        //  returns an accept response
    NULL                        // mark the end of our buttons (we could have more)
    );

  gtk_window_set_title ( GTK_WINDOW ( dialog ) , "VBC Espeak Options");
  gtk_widget_set_usize( GTK_WIDGET ( dialog ) , 600 , 400 );

  /*
   * dialog boxes have a vbox built in we can use 
   */
  main_hbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));

  /*
   * Create the first frame
   */
  gender_frame = gtk_frame_new ("<b>Voice Gender</b>");
  gtk_frame_set_shadow_type (GTK_FRAME (gender_frame), GTK_SHADOW_NONE);
  g_object_set (gtk_frame_get_label_widget (GTK_FRAME (gender_frame)),
                "use-markup", TRUE, NULL);
  gtk_widget_show (gender_frame);

  /*
   * ADD FRAME to the hbox 
   */
  gtk_box_pack_start (GTK_BOX (main_hbox), gender_frame, FALSE, FALSE, 0);//HBOX

  /*
   * Create an alignment widget to indent our child objects 
   */



  /*
   * left aligned, top-aligned, children should fill the box 
   */
  gender_align = gtk_alignment_new (0, 0, 0, 1);


  /*
   * set a left margin of 12 pixels :: Padding
   */
  gtk_alignment_set_padding (GTK_ALIGNMENT (gender_align), 0, 0, 12, 0);
  gtk_widget_show (gender_align);

  /*
   * add alignmnet widget to frame 
   */
  gtk_container_add (GTK_CONTAINER (gender_frame), gender_align);

  /*
   * Create a [vh]box for the radio buttons and add it to the
   * alignment widget inside the frame 
   */

  gender_hbox = gtk_hbox_new (FALSE, 2);        //2 pixels between objects
  gtk_widget_show (gender_hbox);
  gtk_container_add (GTK_CONTAINER (gender_align), gender_hbox);


  /*
   * Create the first radio toggle-box  with a label
   */
  gender_radio_male = gtk_radio_button_new_with_label (NULL, "Male");

  g_signal_connect (gender_radio_male,"toggled", G_CALLBACK (cb_gender_toggled),
  (gpointer)MALE);

  gtk_widget_show (gender_radio_male);

  /*
   *  Create the rest of the radio toggle-box  with label â??
   */
  gender_radio_female = gtk_radio_button_new_with_label (gtk_radio_button_group
                                     (GTK_RADIO_BUTTON (gender_radio_male)), "Female");

  g_signal_connect (gender_radio_female, "toggled", G_CALLBACK (cb_gender_toggled),
  (gpointer)FEMALE);
 
  gtk_widget_show (gender_radio_female);


  /*
   * Pack the two radio buttons into the hbox.
   */

  gtk_box_pack_start (GTK_BOX (gender_hbox), gender_radio_male, TRUE, TRUE, 2);
  gtk_box_pack_start (GTK_BOX (gender_hbox), gender_radio_female, TRUE, TRUE, 2);

  /************************************************************************************
                            End of male/female toggles
   ************************************************************************************/

  /*
   * Create the second frame
   */
  params_frame = gtk_frame_new ("<b>Voice Parameters</b>");
  gtk_frame_set_shadow_type (GTK_FRAME (params_frame), GTK_SHADOW_NONE);
  g_object_set (gtk_frame_get_label_widget (GTK_FRAME (params_frame)),
                "use-markup", TRUE, NULL);
  gtk_widget_show (params_frame);

  /*
   * Add frame to the vbox  [][]
   */
  gtk_box_pack_start (GTK_BOX (main_hbox), params_frame, FALSE, FALSE, 0);

  /*
   * Create an alignment widget to indent our child objects 
   * 
   *
   * left aligned, top-aligned, children should fill the box 
   */
  params_align = gtk_alignment_new (0, 0, 1, 1);
  /*
   * set a left margin of 12 pixels 
   */
  gtk_alignment_set_padding (GTK_ALIGNMENT (params_align), 0, 0, 12, 0);
  gtk_widget_show (params_align);

  /*
   * add alignmnet widget to frame 
   */
  gtk_container_add (GTK_CONTAINER (params_frame), params_align);

  /*
   * create a table for the radio buttons and add it to the
   * alignment widget inside the frame 
   */
  params_table = gtk_table_new (2, 2, FALSE);
  gtk_table_set_row_spacings (GTK_TABLE (params_table), 2);
  gtk_table_set_col_spacings (GTK_TABLE (params_table), 7);
  gtk_widget_show (params_table);
  gtk_container_add (GTK_CONTAINER (params_align), params_table);

  temp_widget = gtk_label_new ("Pitch");

  /*
   * push label left instead of centering
   */
  gtk_misc_set_alignment (GTK_MISC (temp_widget), 0.0, 0.5);
  gtk_widget_show (temp_widget);

  gtk_table_attach (GTK_TABLE (params_table), temp_widget, 0, 1, //column 0 (first)
                    0, 1,                                        //row 1 (second)
                    GTK_FILL, 0,        // Don't grow in size on screen
                    0, 0);

  temp_widget = gtk_label_new ("Speed WPM");
  gtk_misc_set_alignment (GTK_MISC (temp_widget), 0.0, 0.5);//Push label left don't center
  gtk_widget_show (temp_widget);

  gtk_table_attach (GTK_TABLE (params_table), temp_widget, 0, 1, //Column 0 (first)
                    1, 2,                                        //row 1 (second)
                    GTK_FILL, 0,                                 //don't grow in size 
                    0, 0);

  temp_widget = gtk_label_new ("Volume");
  gtk_misc_set_alignment (GTK_MISC (temp_widget), 0.0, 0.5);
  gtk_widget_show (temp_widget);

  gtk_table_attach (GTK_TABLE (params_table), temp_widget, 0, 1,  //Column 0 (first)
                    2, 3,                                         //row 2 (second) 
                    GTK_FILL, 0,                     
                    0, 0);


  temp_widget = gtk_label_new ("Delay");
  gtk_misc_set_alignment (GTK_MISC (temp_widget), 0.0, 0.5);   //push label left
  gtk_widget_show (temp_widget);

  gtk_table_attach (GTK_TABLE (params_table), temp_widget, 0, 1,  //column 0 (first)
                    3, 4,                                         //row 3 (third) 
                    GTK_FILL, 0,        //don't grow in size on screen
                    0, 0);

  /**********
    Set ranges
   *********/                                       
  pitch_scale1 = gtk_hscale_new_with_range (0.0, 100.0, 1.0);
  gtk_range_set_value(GTK_RANGE(pitch_scale1), 17.0);

  gtk_widget_show (pitch_scale1);
  gtk_table_attach (GTK_TABLE (params_table), pitch_scale1, 1, 2,
                    0, 1,       //row 0 (first)
                    GTK_EXPAND | GTK_FILL,      //this part expands when window grows
                    0, 0, 0);
  g_signal_connect (G_OBJECT (pitch_scale1), "value_changed", 
    GTK_SIGNAL_FUNC (hscale_value_changed_pitch), (gpointer) parent_window);

  speedWPM_scale2 = gtk_hscale_new_with_range (80.0, 390.0, 1.0);
  gtk_range_set_value(GTK_RANGE(speedWPM_scale2), 150.0);
  gtk_widget_show (speedWPM_scale2);
  gtk_table_attach (GTK_TABLE (params_table), speedWPM_scale2, 1, 2,    //column 1 (second)
                    1, 2,       //row 0 (first)
                    GTK_EXPAND | GTK_FILL,      //this part expands when window grows
                    0, 0, 0);
  g_signal_connect (G_OBJECT (speedWPM_scale2), "value_changed", 
    GTK_SIGNAL_FUNC (hscale_value_changed_speed), (gpointer) parent_window);


  volume_scale3 = gtk_hscale_new_with_range (0.0, 200.0, 1.0);
  gtk_range_set_value(GTK_RANGE(volume_scale3), 100.0);
  gtk_widget_show (volume_scale3);
  gtk_table_attach (GTK_TABLE (params_table), volume_scale3, 1, 2,      //column 1 (second)
                    2, 3,       //row 0 (first) MOD: 14:1 
                    GTK_EXPAND | GTK_FILL,      //this part expands when window grows
                    0, 0, 0);
  g_signal_connect (G_OBJECT (volume_scale3), "value_changed", 
    GTK_SIGNAL_FUNC (hscale_value_changed_volume), (gpointer) parent_window);

  /*
   * The "delay" is in 10ths of a second between words.  The faster the words
   * are spoken, the more sense it makes to  allow for more delay between
   * words.  For a slow WPM delivery, 3 to 5 tenths should be plenty for
   * DEFAULT.
   */
  delay_scale4 = gtk_hscale_new_with_range (0.0, 100.0, 1.0);
  gtk_range_set_value(GTK_RANGE(delay_scale4), 5.0);
  gtk_widget_show (delay_scale4);
  gtk_table_attach (GTK_TABLE (params_table), delay_scale4, 1, 2,       //column 1 (second)
                    3, 4,       //row 0 (first) MOD: 14:1 
                    GTK_EXPAND | GTK_FILL,   //this part expands when window grows
                    0, 0, 0);

  g_signal_connect (G_OBJECT (delay_scale4), "value_changed", 
    GTK_SIGNAL_FUNC (hscale_value_changed_delay), (gpointer) parent_window);

  /*****
   Print gender, pitch, speed, volume, delay to stdout.
   *****/
  fprintf(stdout,"gender = (%d), patch = %g, speed = %g, volume = %g delay = %g\n",
  valueGender, valuePitch, valueSpeed, valueVolume, valueDelay);





  /*
   * Run the dialog (a main loop starts automatically)
   */
  gtk_dialog_run (GTK_DIALOG (dialog));

  /*
   * Return 0 if exit is successful.
   */
  return 0;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]