Blame hdspconf/src/HC_ClockSource.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_ClockSource.h"
Packit 427e91
Packit 427e91
extern const char *freqs[10];
Packit 427e91
Packit 427e91
void clock_source_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 src = 0;
Packit 427e91
	HC_ClockSource *cs = (HC_ClockSource *)arg;
Packit 427e91
	HC_CardPane *pane = (HC_CardPane *)(cs->parent());
Packit 427e91
	Fl_Round_Button *source = (Fl_Round_Button *)w;
Packit 427e91
	if (source == cs->autosync) {
Packit 427e91
		src = 0;
Packit 427e91
	} else if (source == cs->khz32) {
Packit 427e91
		src = 1;
Packit 427e91
	} else if (source == cs->khz44_1) {
Packit 427e91
		src = 2;
Packit 427e91
	} else if (source == cs->khz48) {
Packit 427e91
		src = 3;
Packit 427e91
	} else if (source == cs->khz64) {
Packit 427e91
		src = 4;
Packit 427e91
	} else if (source == cs->khz88_2) {
Packit 427e91
		src = 5;
Packit 427e91
	} else if (source == cs->khz96) {
Packit 427e91
		src = 6;
Packit 427e91
	} else if (source == cs->khz128) {
Packit 427e91
		src = 7;
Packit 427e91
	} else if (source == cs->khz176_4) {
Packit 427e91
		src = 8;
Packit 427e91
	} else if (source == cs->khz192) {
Packit 427e91
		src = 9;
Packit 427e91
	}
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, "Sample Clock Source");
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, src);
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_PCM);
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
HC_ClockSource::HC_ClockSource(int x, int y, int w, int h):Fl_Group(x, y, w, h, "Sample Clock Source")
Packit 427e91
{
Packit 427e91
	int i = 0;
Packit 427e91
	box(FL_ENGRAVED_FRAME);
Packit 427e91
	label("Sample Clock Source");
Packit 427e91
	labelsize(10);
Packit 427e91
	align(FL_ALIGN_TOP|FL_ALIGN_LEFT);
Packit 427e91
	autosync = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, "AutoSync");
Packit 427e91
	autosync->callback(clock_source_cb, (void *)this);
Packit 427e91
	khz32 = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, freqs[0]);
Packit 427e91
	khz32->callback(clock_source_cb, (void *)this);
Packit 427e91
	khz44_1 = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, freqs[1]);
Packit 427e91
	khz44_1->callback(clock_source_cb, (void *)this);
Packit 427e91
	khz48 = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, freqs[2]);
Packit 427e91
	khz48->callback(clock_source_cb, (void *)this);
Packit 427e91
	khz64 = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, freqs[3]);
Packit 427e91
	khz64->callback(clock_source_cb, (void *)this);
Packit 427e91
	khz88_2 = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, freqs[4]);
Packit 427e91
	khz88_2->callback(clock_source_cb, (void *)this);
Packit 427e91
	khz96 = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, freqs[5]);
Packit 427e91
	khz96->callback(clock_source_cb, (void *)this);
Packit 427e91
	if (((HC_CardPane *)parent())->type == H9632) {
Packit 427e91
	    khz128 = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, freqs[7]);
Packit 427e91
	    khz128->callback(clock_source_cb, (void *)this);
Packit 427e91
	    khz128->labelsize(10);
Packit 427e91
	    khz128->type(FL_RADIO_BUTTON);
Packit 427e91
	    khz176_4 = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, freqs[8]);
Packit 427e91
	    khz176_4->callback(clock_source_cb, (void *)this);
Packit 427e91
	    khz176_4->labelsize(10);
Packit 427e91
	    khz176_4->type(FL_RADIO_BUTTON);
Packit 427e91
	    khz192 = new Fl_Round_Button(x+10, y+V_STEP*i++, w-20, V_STEP, freqs[9]);
Packit 427e91
	    khz192->callback(clock_source_cb, (void *)this);
Packit 427e91
	    khz192->labelsize(10);
Packit 427e91
	    khz192->type(FL_RADIO_BUTTON);
Packit 427e91
	}
Packit 427e91
	autosync->labelsize(10);
Packit 427e91
	autosync->type(FL_RADIO_BUTTON);
Packit 427e91
	khz32->labelsize(10);
Packit 427e91
	khz32->type(FL_RADIO_BUTTON);
Packit 427e91
	khz44_1->labelsize(10);
Packit 427e91
	khz44_1->type(FL_RADIO_BUTTON);
Packit 427e91
	khz48->labelsize(10);
Packit 427e91
	khz48->type(FL_RADIO_BUTTON);
Packit 427e91
	khz64->labelsize(10);
Packit 427e91
	khz64->type(FL_RADIO_BUTTON);
Packit 427e91
	khz88_2->labelsize(10);
Packit 427e91
	khz88_2->type(FL_RADIO_BUTTON);
Packit 427e91
	khz96->labelsize(10);
Packit 427e91
	khz96->type(FL_RADIO_BUTTON);
Packit 427e91
	end();
Packit 427e91
}
Packit 427e91
Packit 427e91
void HC_ClockSource::setSource(unsigned char s)
Packit 427e91
{
Packit 427e91
    if (s < children()) {
Packit 427e91
	if (((Fl_Round_Button *)child(s))->value() != 1)
Packit 427e91
	    ((Fl_Round_Button *)child(s))->setonly();
Packit 427e91
    }
Packit 427e91
}
Packit 427e91