Blame hdspconf/src/HC_PrefSyncRef.cxx

Packit 427e91
/*
Packit 427e91
 *   HDSPConf
Packit 427e91
 *    
Packit 427e91
 *   Copyright (C) 2003 Thomas Charbonnel (thomas@undata.org)
Packit 427e91
 *    
Packit 427e91
 *   This program is free software; you can redistribute it and/or modify
Packit 427e91
 *   it under the terms of the GNU General Public License as published by
Packit 427e91
 *   the Free Software Foundation; either version 2 of the License, or
Packit 427e91
 *   (at your option) any later version.
Packit 427e91
 *
Packit 427e91
 *   This program is distributed in the hope that it will be useful,
Packit 427e91
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 427e91
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 427e91
 *   GNU General Public License for more details.
Packit 427e91
 *
Packit 427e91
 *   You should have received a copy of the GNU General Public License
Packit 427e91
 *   along with this program; if not, write to the Free Software
Packit 427e91
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Packit 427e91
 */
Packit 427e91
Packit 427e91
#pragma implementation
Packit 427e91
#include "HC_PrefSyncRef.h"
Packit 427e91
Packit 427e91
void pref_sync_ref_cb(Fl_Widget *w, void *arg)
Packit 427e91
{
Packit 427e91
    int err;
Packit 427e91
    char card_name[6];
Packit 427e91
    snd_ctl_elem_value_t *ctl;
Packit 427e91
    snd_ctl_elem_id_t *id;
Packit 427e91
    snd_ctl_t *handle;
Packit 427e91
    int ref = 0;
Packit 427e91
    HC_PrefSyncRef *psr = (HC_PrefSyncRef *)arg;
Packit 427e91
    HC_CardPane *pane = (HC_CardPane *)(psr->parent());
Packit 427e91
    Fl_Round_Button *source = (Fl_Round_Button *)w;
Packit 427e91
    if (source == psr->word_clock) {
Packit 427e91
	ref = 0;
Packit 427e91
    } else if (source == psr->spdif) {
Packit 427e91
	ref = 1;
Packit 427e91
    } else if (source == psr->adat1) {
Packit 427e91
	ref = 2;
Packit 427e91
    } else if (source == psr->adat_sync) {
Packit 427e91
	ref = 3;
Packit 427e91
    } else if (source == psr->adat2) {
Packit 427e91
	ref = 4;
Packit 427e91
    } else if (source == psr->adat3) {
Packit 427e91
	ref = 5;
Packit 427e91
    }
Packit 427e91
    snprintf(card_name, 6, "hw:%i", pane->alsa_index);
Packit 427e91
    snd_ctl_elem_value_alloca(&ctl;;
Packit 427e91
    snd_ctl_elem_id_alloca(&id;;
Packit 427e91
    snd_ctl_elem_id_set_name(id, "Preferred Sync Reference");
Packit 427e91
    snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
    snd_ctl_elem_id_set_index(id, 0);
Packit 427e91
    snd_ctl_elem_value_set_id(ctl, id);
Packit 427e91
    snd_ctl_elem_value_set_enumerated(ctl, 0, ref);
Packit 427e91
    if ((err = snd_ctl_open(&handle, card_name, SND_CTL_NONBLOCK)) < 0) {
Packit 427e91
	fprintf(stderr, "Error opening ctl interface on card %s\n", card_name); 
Packit 427e91
	return;
Packit 427e91
    }
Packit 427e91
    if ((err = snd_ctl_elem_write(handle, ctl)) < 0) {
Packit 427e91
	snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_HWDEP);
Packit 427e91
	snd_ctl_elem_value_set_id(ctl, id);
Packit 427e91
	if ((err = snd_ctl_elem_write(handle, ctl)) < 0) {
Packit 427e91
	    fprintf(stderr, "Error accessing ctl interface on card %s\n", card_name); 
Packit 427e91
	    snd_ctl_close(handle);
Packit 427e91
	    return;
Packit 427e91
	}
Packit 427e91
    }
Packit 427e91
    snd_ctl_close(handle);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
HC_PrefSyncRef::HC_PrefSyncRef(int x, int y, int w, int h):Fl_Group(x, y, w, h, "Pref. Sync Ref")
Packit 427e91
{
Packit 427e91
	int i = 0;
Packit 427e91
	if (((HC_CardPane *)parent())->type == Multiface || ((HC_CardPane *)parent())->type == H9632) {
Packit 427e91
	    adat_name = "ADAT In";
Packit 427e91
	} else {
Packit 427e91
	    adat_name = "ADAT1 In";
Packit 427e91
	}
Packit 427e91
	box(FL_ENGRAVED_FRAME);;
Packit 427e91
	label("Pref. Sync Ref");
Packit 427e91
	labelsize(10);
Packit 427e91
	align(FL_ALIGN_TOP|FL_ALIGN_LEFT);
Packit 427e91
	word_clock = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, "Word Clock");
Packit 427e91
	word_clock->callback(pref_sync_ref_cb, (void *)this);
Packit 427e91
	if (((HC_CardPane *)parent())->type != H9632) {
Packit 427e91
	    adat_sync = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, "ADAT Sync");
Packit 427e91
	    adat_sync->callback(pref_sync_ref_cb, (void *)this);
Packit 427e91
	    adat_sync->labelsize(10);
Packit 427e91
	    adat_sync->type(FL_RADIO_BUTTON);
Packit 427e91
	}
Packit 427e91
	spdif = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, "SPDIF In");
Packit 427e91
	spdif->callback(pref_sync_ref_cb, (void *)this);
Packit 427e91
	adat1 = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, adat_name);
Packit 427e91
	adat1->callback(pref_sync_ref_cb, (void *)this);
Packit 427e91
	if (((HC_CardPane *)parent())->type != Multiface && ((HC_CardPane *)parent())->type != H9632) {
Packit 427e91
	    adat2 = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, "ADAT2 In");
Packit 427e91
	    adat2->labelsize(10);
Packit 427e91
	    adat2->type(FL_RADIO_BUTTON);
Packit 427e91
	    adat2->callback(pref_sync_ref_cb, (void *)this);
Packit 427e91
	    adat3 = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, "ADAT3 In");
Packit 427e91
	    adat3->labelsize(10);
Packit 427e91
	    adat3->type(FL_RADIO_BUTTON);
Packit 427e91
	    adat3->callback(pref_sync_ref_cb, (void *)this);
Packit 427e91
	}	
Packit 427e91
	adat1->labelsize(10);
Packit 427e91
	adat1->type(FL_RADIO_BUTTON);
Packit 427e91
	spdif->labelsize(10);
Packit 427e91
	spdif->type(FL_RADIO_BUTTON);
Packit 427e91
	word_clock->labelsize(10);
Packit 427e91
	word_clock->type(FL_RADIO_BUTTON);
Packit 427e91
	end();	
Packit 427e91
}
Packit 427e91
Packit 427e91
void HC_PrefSyncRef::setRef(int r)
Packit 427e91
{
Packit 427e91
	switch (r) {
Packit 427e91
	case 0:
Packit 427e91
	    if (word_clock->value() != 1)
Packit 427e91
		word_clock->setonly();
Packit 427e91
	    break;
Packit 427e91
	case 1:
Packit 427e91
	    if (spdif->value() != 1)
Packit 427e91
		spdif->setonly();
Packit 427e91
	    break;
Packit 427e91
	case 2:
Packit 427e91
	    if (adat1->value() != 1)
Packit 427e91
		adat1->setonly();
Packit 427e91
	    break;
Packit 427e91
	case 3:
Packit 427e91
	    if (((HC_CardPane *)parent())->type != H9632)
Packit 427e91
		if (adat_sync->value() != 1)
Packit 427e91
		    adat_sync->setonly();
Packit 427e91
	    break;
Packit 427e91
	case 4:
Packit 427e91
	    if (((HC_CardPane *)parent())->type == H9652 || ((HC_CardPane *)parent())->type == Digiface)
Packit 427e91
		if (adat2->value() != 1)
Packit 427e91
		    adat2->setonly();
Packit 427e91
	    break;		    	    
Packit 427e91
	case 5:
Packit 427e91
	    if (((HC_CardPane *)parent())->type == H9652 || ((HC_CardPane *)parent())->type == Digiface)
Packit 427e91
		if (adat3->value() != 1)
Packit 427e91
		    adat3->setonly();
Packit 427e91
	    break;		    	    
Packit 427e91
	}
Packit 427e91
}
Packit 427e91