outpanel.c 10.8 KB
Newer Older
1 2 3 4
/*
 *
 *  postfish
 *    
Monty Montgomery's avatar
Monty Montgomery committed
5
 *      Copyright (C) 2002-2005 Monty
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
 *
 *  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);
73 74
  if(state.monitor_active)gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state.monitor_active),outset.panel_active[0]);
  if(state.stdout_active)gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state.stdout_active),outset.panel_active[1]);
75 76 77

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

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

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

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


  config_get_vector("output_stdout_source",bank,0,0,0,OUTPUT_CHANNELS,outset.stdout.source);
  for(i=0;i<OUTPUT_CHANNELS;i++)
102 103 104
    if(state.stdout.source[i])
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state.stdout.source[i]),
                                   outset.stdout.source[i]);
105 106 107

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

}

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

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

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);
179
      // careful; this breaks (cosmetically) for OUTPUT_CHANNELS > 8
180 181 182 183 184 185 186 187 188 189 190 191 192 193
      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;
194
    GtkWidget *menu=gtk_combo_box_new_text();
195 196 197
    
    if(devp){
      /* device selection */
198 199
      for(i=0;i<monitor_entries;i++)
	gtk_combo_box_append_text (GTK_COMBO_BOX (menu), monitor_list[i].name);
200
      
201 202
      if(i==0)
	gtk_combo_box_append_text (GTK_COMBO_BOX (menu), "stdout");
203

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

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

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

    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;
237
    GtkWidget *menu=gtk_combo_box_new_text();
238 239
    char *formats[]={"auto","1","2","4","6","8"};
    
240 241
    for(i=0;i<6;i++)
      gtk_combo_box_append_text (GTK_COMBO_BOX (menu), formats[i]);
242

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

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

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

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

271
    os->depth=menu;
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
  }
  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 ",
300
					    output_stdout_ao,
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 328
					    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);
}