outpanel.c 10.6 KB
Newer Older
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
/*
 *
 *  postfish
 *    
 *      Copyright (C) 2002-2004 Monty
 *
 *  Postfish 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, or (at your option)
 *  any later version.
 *   
 *  Postfish 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 Postfish; see the file COPYING.  If not, write to the
 *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * 
 */

#include "postfish.h"
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "readout.h"
#include "multibar.h"
#include "mainpanel.h"
#include "subpanel.h"
#include "output.h"
#include "outpanel.h"
#include "config.h"

typedef struct {
  GtkWidget *source[OUTPUT_CHANNELS];
  GtkWidget *device;
  GtkWidget *format;
  GtkWidget *ch;
  GtkWidget *depth;
} outsub_state;

typedef struct {
  GtkWidget *monitor_active;
  GtkWidget *stdout_active;

  outsub_state monitor;
  outsub_state stdout;
} outpanel_state;

outpanel_state state;

void outpanel_state_to_config(int bank){
  config_set_vector("output_active",bank,0,0,0,2,outset.panel_active);

  config_set_vector("output_monitor_source",bank,0,0,0,OUTPUT_CHANNELS,outset.monitor.source);
  config_set_integer("output_monitor_set",bank,0,0,0,0,outset.monitor.device);
  config_set_integer("output_monitor_set",bank,0,0,0,1,outset.monitor.bytes);
  config_set_integer("output_monitor_set",bank,0,0,0,2,outset.monitor.ch);
  config_set_integer("output_monitor_set",bank,0,0,0,3,outset.monitor.format);

  config_set_vector("output_stdout_source",bank,0,0,0,OUTPUT_CHANNELS,outset.stdout.source);
  config_set_integer("output_stdout_set",bank,0,0,0,0,outset.stdout.device);
  config_set_integer("output_stdout_set",bank,0,0,0,1,outset.stdout.bytes);
  config_set_integer("output_stdout_set",bank,0,0,0,2,outset.stdout.ch);
  config_set_integer("output_stdout_set",bank,0,0,0,3,outset.stdout.format);
}

void outpanel_state_from_config(int bank){
  int i;

  config_get_vector("output_active",bank,0,0,0,2,outset.panel_active);
  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state.monitor_active),outset.panel_active[0]);
  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state.stdout_active),outset.panel_active[1]);

  config_get_vector("output_monitor_source",bank,0,0,0,OUTPUT_CHANNELS,outset.monitor.source);
  for(i=0;i<OUTPUT_CHANNELS;i++)
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state.monitor.source[i]),
				 outset.monitor.source[i]);

  config_get_sigat("output_monitor_set",bank,0,0,0,0,&outset.monitor.device);
82 83

  /* don't set a device that doesn't exist */
84 85
  if(outset.monitor.device>=monitor_entries)outset.monitor.device=monitor_entries-1;
  if(state.monitor.device)
86
    gtk_combo_box_set_active(GTK_COMBO_BOX(state.monitor.device),outset.monitor.device);
87

88 89
  config_get_sigat("output_monitor_set",bank,0,0,0,1,&outset.monitor.bytes);
  if(state.monitor.depth)
90
    gtk_combo_box_set_active(GTK_COMBO_BOX(state.monitor.depth),outset.monitor.bytes);
91 92
  config_get_sigat("output_monitor_set",bank,0,0,0,2,&outset.monitor.ch);
  if(state.monitor.ch)
93
    gtk_combo_box_set_active(GTK_COMBO_BOX(state.monitor.ch),outset.monitor.ch);
94 95
  config_get_sigat("output_monitor_set",bank,0,0,0,3,&outset.monitor.format);
  if(state.monitor.format)
96
    gtk_combo_box_set_active(GTK_COMBO_BOX(state.monitor.format),outset.monitor.format);
97 98 99 100 101 102 103 104 105


  config_get_vector("output_stdout_source",bank,0,0,0,OUTPUT_CHANNELS,outset.stdout.source);
  for(i=0;i<OUTPUT_CHANNELS;i++)
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state.stdout.source[i]),
				 outset.stdout.source[i]);

  config_get_sigat("output_stdout_set",bank,0,0,0,0,&outset.stdout.device);
  if(state.stdout.device)
106
    gtk_combo_box_set_active(GTK_COMBO_BOX(state.stdout.device),outset.stdout.device);
107 108
  config_get_sigat("output_stdout_set",bank,0,0,0,1,&outset.stdout.bytes);
  if(state.stdout.depth)
109
    gtk_combo_box_set_active(GTK_COMBO_BOX(state.stdout.depth),outset.stdout.bytes);
110 111
  config_get_sigat("output_stdout_set",bank,0,0,0,2,&outset.stdout.ch);
  if(state.stdout.ch)
112
    gtk_combo_box_set_active(GTK_COMBO_BOX(state.stdout.ch),outset.stdout.ch);
113 114
  config_get_sigat("output_stdout_set",bank,0,0,0,3,&outset.stdout.format);
  if(state.stdout.format)
115
    gtk_combo_box_set_active(GTK_COMBO_BOX(state.stdout.format),outset.stdout.format);
116 117 118 119 120 121 122


}

static void menuchange(GtkWidget *w,gpointer in){
  sig_atomic_t *var=(sig_atomic_t *)in;

123
  *var=gtk_combo_box_get_active(GTK_COMBO_BOX(w));
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
}

static void buttonchange(GtkWidget *w,gpointer in){
  sig_atomic_t *var=(sig_atomic_t *)in;

  *var=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
}


static GtkWidget *outpanel_subpanel(postfish_mainpanel *mp,
				    subpanel_generic *panel, 
				    output_subsetting *set,
				    char *prompt,
				    int devp,
				    int active,
				    outsub_state *os){

  GtkWidget *frame=gtk_frame_new(prompt);
  GtkWidget *table=gtk_table_new(4,3,0);
  
  GtkWidget *l1=gtk_label_new("active channels ");
  GtkWidget *l2=gtk_label_new(devp?"output device ":"output format ");
  GtkWidget *l3=gtk_label_new("output channels ");
  GtkWidget *l4=gtk_label_new("output bit depth ");

  GtkWidget *b1=gtk_hbox_new(1,0);
  GtkWidget *b2=gtk_hbox_new(1,0);
  GtkWidget *b3=gtk_hbox_new(1,0);
  GtkWidget *b4=gtk_hbox_new(1,0);

  gtk_frame_set_shadow_type(GTK_FRAME(frame),GTK_SHADOW_ETCHED_IN);
  gtk_container_set_border_width(GTK_CONTAINER(table),4);

  gtk_misc_set_alignment(GTK_MISC(l1),1.,.5);
  gtk_misc_set_alignment(GTK_MISC(l2),1.,.5);
  gtk_misc_set_alignment(GTK_MISC(l3),1.,.5);
  gtk_misc_set_alignment(GTK_MISC(l4),1.,.5);

  gtk_table_attach_defaults(GTK_TABLE(table),l1,0,1,0,1);
  gtk_table_attach_defaults(GTK_TABLE(table),l2,0,1,1,2);
  gtk_table_attach_defaults(GTK_TABLE(table),l3,0,1,2,3);
  gtk_table_attach_defaults(GTK_TABLE(table),l4,0,1,3,4);

  /* channel buttonx0rz */
  {
    int i;
    char buffer[80];
    for(i=0;i<OUTPUT_CHANNELS;i++){
      GtkWidget *b;
      sprintf(buffer," %d ",i+1);

      b=gtk_toggle_button_new_with_label(buffer);
      
      gtk_box_pack_start(GTK_BOX(b1),b,0,0,0);
178
      // careful; this breaks (cosmetically) for OUTPUT_CHANNELS > 8
179 180 181 182 183 184 185 186 187 188 189 190 191 192
      gtk_widget_add_accelerator (b, "activate", mp->group, GDK_1+i, 0, 0); 
      gtk_widget_set_sensitive(b,active);
      g_signal_connect (G_OBJECT (b), "clicked",
			G_CALLBACK (buttonchange), &set->source[i]);

      if(i<2)gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b),1);
      os->source[i]=b;
    }
    gtk_table_attach_defaults(GTK_TABLE(table),b1,1,3,0,1);
  }


  {
    int i;
193
    GtkWidget *menu=gtk_combo_box_new_text();
194 195 196
    
    if(devp){
      /* device selection */
197 198
      for(i=0;i<monitor_entries;i++)
	gtk_combo_box_append_text (GTK_COMBO_BOX (menu), monitor_list[i].name);
199
      
200 201
      if(i==0)
	gtk_combo_box_append_text (GTK_COMBO_BOX (menu), "stdout");
202

203
      g_signal_connect (G_OBJECT (menu), "changed",
204
			G_CALLBACK (menuchange), &set->device);
205 206
      
      os->device=menu;
207 208 209 210 211 212 213
      os->format=0;
    }else{
      
      /* format selection */
      int i;
      char *formats[]={"WAV","AIFF-C","raw (little endian)","raw (big endian)"};
      
214 215 216 217
      for(i=0;i<4;i++)
	gtk_combo_box_append_text (GTK_COMBO_BOX (menu), formats[i]);

      g_signal_connect (G_OBJECT (menu), "changed",
218
			G_CALLBACK (menuchange), &set->format);
219
      os->format=menu;
220 221 222
      os->device=0;
    }

223
    gtk_combo_box_set_active(GTK_COMBO_BOX(menu),0);
224
    
225
    gtk_box_pack_start(GTK_BOX(b2),menu,1,1,0);
226 227 228 229 230 231 232 233 234 235

    gtk_widget_set_sensitive(menu,active);

  }
  gtk_table_attach(GTK_TABLE(table),b2,1,2,1,2,GTK_FILL,0,0,0);


  {
    /* channels selection */
    int i;
236
    GtkWidget *menu=gtk_combo_box_new_text();
237 238
    char *formats[]={"auto","1","2","4","6","8"};
    
239 240
    for(i=0;i<6;i++)
      gtk_combo_box_append_text (GTK_COMBO_BOX (menu), formats[i]);
241

242
    gtk_combo_box_set_active(GTK_COMBO_BOX(menu),0);
243
    
244
    gtk_box_pack_start(GTK_BOX(b3),menu,1,1,0);
245
    gtk_widget_set_sensitive(menu,active);
246
    g_signal_connect (G_OBJECT (menu), "changed",
247
		      G_CALLBACK (menuchange), &set->ch);
248
    os->ch=menu;
249 250 251 252 253 254 255
  }
  gtk_table_attach(GTK_TABLE(table),b3,1,2,2,3,GTK_FILL,0,0,0);
  

  {
    /* bit depth selection */
    int i;
256
    GtkWidget *menu=gtk_combo_box_new_text();
257 258
    char *formats[]={"auto","8","16","24"};
    
259 260
    for(i=0;i<4;i++)
      gtk_combo_box_append_text (GTK_COMBO_BOX (menu), formats[i]);
261

262
    gtk_combo_box_set_active(GTK_COMBO_BOX(menu),0);
263
    
264
    gtk_box_pack_start(GTK_BOX(b4),menu,1,1,0);
265 266
    gtk_widget_set_sensitive(menu,active);

267
    g_signal_connect (G_OBJECT (menu), "changed",
268 269
		      G_CALLBACK (menuchange), &set->bytes);

270
    os->depth=menu;
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
  }
  gtk_table_attach(GTK_TABLE(table),b4,1,2,3,4,GTK_FILL,0,0,0);

  gtk_table_set_row_spacing(GTK_TABLE(table),0,5);

  gtk_container_add(GTK_CONTAINER(frame),table);
  return frame;
}

void outpanel_create(postfish_mainpanel *mp,
		      GtkWidget *windowbutton,
		      GtkWidget **activebutton){

  char *shortcuts[]={"mOn"," o "};

  subpanel_generic *panel=subpanel_create(mp,windowbutton,activebutton,
					  outset.panel_active,
					  &outset.panel_visible,
					  "_Output configuration",shortcuts,
					  0,2);
  
  GtkWidget *box=gtk_hbox_new(1,0);
  GtkWidget *monitor_panel=outpanel_subpanel(mp,panel,&outset.monitor,
					     " audio monitor output ",
					     1,output_monitor_available,
					     &state.monitor);
  GtkWidget *stdout_panel=outpanel_subpanel(mp,panel,&outset.stdout,
					    " standard output ",
					    output_stdout_device,
					    output_stdout_available,
					    &state.stdout);
  
  gtk_box_pack_start(GTK_BOX(box),monitor_panel,0,0,0);
  gtk_box_pack_start(GTK_BOX(box),stdout_panel,0,0,2);

  if(!output_monitor_available)gtk_widget_set_sensitive(activebutton[0],0);
  if(!output_monitor_available)gtk_widget_set_sensitive(panel->subpanel_activebutton[0],0);
  if(!output_stdout_available)gtk_widget_set_sensitive(activebutton[1],0);
  if(!output_stdout_available)gtk_widget_set_sensitive(panel->subpanel_activebutton[1],0);

  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(activebutton[0]),1);
  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(activebutton[1]),1);

  gtk_container_add(GTK_CONTAINER(panel->subpanel_box),box);
  subpanel_show_all_but_toplevel(panel);

  state.monitor_active=activebutton[0];
  state.stdout_active=activebutton[1];
}

void outpanel_monitor_off(){
  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state.monitor_active),0);
}

void outpanel_stdout_off(){
  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state.stdout_active),0);
}