Blame hdspconf/src/hdspconf.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
#include <stdio.h>
Packit 427e91
#include <stdlib.h>
Packit 427e91
#include <getopt.h>
Packit 427e91
#include <errno.h>
Packit 427e91
#include <sys ioctl.h="">
Packit 427e91
#include <alsa asoundlib.h="">
Packit 427e91
#include <alsa sound="" hdsp.h="">
Packit 427e91
#include <fl fl.h="">
Packit 427e91
#include <fl fl_window.h="">
Packit 427e91
#include <fl fl_group.h="">
Packit 427e91
#include <fl fl_tabs.h="">
Packit 427e91
#include "HC_CardPane.h"
Packit 427e91
#include "HC_XpmRenderer.h"
Packit 427e91
#include "pixmaps.h"
Packit 427e91
#include "HC_AboutText.h"
Packit 427e91
#include "defines.h"
Packit 427e91
Packit 427e91
//#define GUI_TEST
Packit 427e91
Packit 427e91
class HC_CardPane;
Packit 427e91
class HC_XpmRenderer;
Packit 427e91
class HC_AboutText;
Packit 427e91
Packit 427e91
static void refresh_cb(void *arg)
Packit 427e91
{
Packit 427e91
    Fl_Tabs *tabs = (Fl_Tabs *)arg;
Packit 427e91
    int err;
Packit 427e91
    snd_hwdep_t *hw;
Packit 427e91
    char card_name[6];
Packit 427e91
    hdsp_config_info_t config_info;
Packit 427e91
    
Packit 427e91
    for (int i = 0; i < tabs->children()-1 ; ++i) {
Packit 427e91
	HC_CardPane *pane = (HC_CardPane *)tabs->child(i);
Packit 427e91
	if (!pane->visible()) {
Packit 427e91
	    break;
Packit 427e91
	}
Packit 427e91
	snprintf(card_name, 6, "hw:%i", pane->alsa_index);
Packit 427e91
Packit 427e91
	if ((err = snd_hwdep_open(&hw, card_name, SND_HWDEP_OPEN_READ)) != 0) {
Packit 427e91
	    fprintf(stderr, "Error opening hwdep device on card %s.\n", card_name);
Packit 427e91
	    break;
Packit 427e91
	}
Packit 427e91
    
Packit 427e91
	if ((err = snd_hwdep_ioctl(hw, SNDRV_HDSP_IOCTL_GET_CONFIG_INFO, (void *)&config_info)) < 0) {
Packit 427e91
	    fprintf(stderr, "Hwdep ioctl error on card %s.\n", card_name);
Packit 427e91
	    snd_hwdep_close(hw);
Packit 427e91
	    break;
Packit 427e91
	}
Packit 427e91
Packit 427e91
	snd_hwdep_close(hw);
Packit 427e91
Packit 427e91
	pane->sync_ref->setRef(config_info.pref_sync_ref);
Packit 427e91
	pane->spdif_freq->setFreq(config_info.spdif_sample_rate);
Packit 427e91
	pane->sync_check->setAdat1Status(config_info.adat_sync_check[0]);
Packit 427e91
	pane->sync_check->setSpdifStatus(config_info.spdif_sync_check);
Packit 427e91
	pane->sync_check->setWCStatus(config_info.wordclock_sync_check);
Packit 427e91
	if (pane->type != H9632) {
Packit 427e91
	    pane->sync_check->setAdatSyncStatus(config_info.adatsync_sync_check);
Packit 427e91
	}
Packit 427e91
	if (pane->type == Digiface || pane->type == H9652) {
Packit 427e91
	    pane->sync_check->setAdat2Status(config_info.adat_sync_check[1]);
Packit 427e91
	    pane->sync_check->setAdat3Status(config_info.adat_sync_check[2]);
Packit 427e91
	}
Packit 427e91
	pane->spdif_in->setInput(config_info.spdif_in);
Packit 427e91
	if (pane->spdif_out->lock == 0) {
Packit 427e91
	    pane->spdif_out->setOut(config_info.spdif_out);
Packit 427e91
	    pane->spdif_out->setProfessional(config_info.spdif_professional);
Packit 427e91
	    pane->spdif_out->setEmphasis(config_info.spdif_emphasis);
Packit 427e91
	    pane->spdif_out->setNonaudio(config_info.spdif_nonaudio);
Packit 427e91
	}
Packit 427e91
	pane->clock_source->setSource(config_info.clock_source);	
Packit 427e91
	pane->autosync_ref->setRef(config_info.autosync_ref);
Packit 427e91
	pane->autosync_ref->setFreq(config_info.autosync_sample_rate);
Packit 427e91
	pane->system_clock->setMode(config_info.system_clock_mode);
Packit 427e91
	pane->system_clock->setFreq(config_info.system_sample_rate);
Packit 427e91
	if (pane->type == H9632) {
Packit 427e91
	    pane->input_level->setInputLevel(config_info.ad_gain);
Packit 427e91
	    pane->output_level->setOutputLevel(config_info.da_gain);
Packit 427e91
	    pane->phones->setPhones(config_info.phone_gain);
Packit 427e91
	    pane->breakout_cable->setXlr(config_info.xlr_breakout_cable);
Packit 427e91
	}
Packit 427e91
	if (pane->type == H9632 || pane->type == H9652) {
Packit 427e91
	    pane->aeb->setAdatInternal(config_info.analog_extension_board);
Packit 427e91
	}
Packit 427e91
    }
Packit 427e91
Packit 427e91
    Fl::add_timeout(0.3, refresh_cb, arg);
Packit 427e91
    return;
Packit 427e91
}
Packit 427e91
Packit 427e91
int main(int argc, char **argv)
Packit 427e91
{
Packit 427e91
    Fl_Window *window;
Packit 427e91
    Fl_Tabs   *tabs;
Packit 427e91
    HC_CardPane  *card_panes[4];
Packit 427e91
    HC_XpmRenderer *lad_banner;
Packit 427e91
    HC_XpmRenderer *alsa_logo;
Packit 427e91
    HC_XpmRenderer *rme_logo;
Packit 427e91
    HC_AboutText *about_text;
Packit 427e91
    Fl_Group  *about_pane;
Packit 427e91
    char *name;
Packit 427e91
    int card;
Packit 427e91
    HDSP_IO_Type hdsp_cards[4];
Packit 427e91
    int alsa_index[4];
Packit 427e91
    snd_ctl_card_info_t *info;
Packit 427e91
    snd_pcm_info_t *pcminfo;
Packit 427e91
    int cards = 0;
Packit 427e91
    
Packit 427e91
    snd_ctl_card_info_alloca(&info);
Packit 427e91
    snd_pcm_info_alloca(&pcminfo);    
Packit 427e91
    card = -1;
Packit 427e91
    printf("\nHDSPConf %s - Copyright (C) 2003 Thomas Charbonnel <thomas@undata.org>\n", VERSION);
Packit 427e91
    printf("This program comes WITH ABSOLUTELY NO WARRANTY\n");
Packit 427e91
    printf("HDSPConf is free software, see the file copying for details\n\n");
Packit 427e91
    printf("Looking for HDSP cards :\n");
Packit 427e91
Packit 427e91
#ifdef GUI_TEST
Packit 427e91
    hdsp_cards[0] = Digiface;
Packit 427e91
    alsa_index[0] = 0;
Packit 427e91
    hdsp_cards[1] = H9652;
Packit 427e91
    alsa_index[1] = 1;
Packit 427e91
    hdsp_cards[2] = Multiface;
Packit 427e91
    alsa_index[2] = 2;
Packit 427e91
    hdsp_cards[3] = H9632;
Packit 427e91
    alsa_index[3] = 3;
Packit 427e91
    cards = 4;
Packit 427e91
#else
Packit 427e91
    while (snd_card_next(&card) >= 0 && cards < 4) {
Packit 427e91
	if (card < 0) {
Packit 427e91
	    break;
Packit 427e91
	} else {
Packit 427e91
	    snd_card_get_longname(card, &name);
Packit 427e91
	    printf("Card %d : %s\n", card, name);
Packit 427e91
	    if (!strncmp(name, "RME Hammerfall DSP + Multiface", 30)) {
Packit 427e91
		printf("Multiface found !\n");
Packit 427e91
		hdsp_cards[cards] = Multiface;
Packit 427e91
		alsa_index[cards] = card;
Packit 427e91
		cards++;
Packit 427e91
	    } else if (!strncmp(name, "RME Hammerfall DSP + Digiface", 29)) {
Packit 427e91
		printf("Digiface found !\n");
Packit 427e91
		hdsp_cards[cards] = Digiface;
Packit 427e91
		alsa_index[cards] = card;
Packit 427e91
		cards++;
Packit 427e91
	    } else if (!strncmp(name, "RME Hammerfall HDSP 9652", 24)) {
Packit 427e91
		printf("HDSP 9652 found !\n");
Packit 427e91
		hdsp_cards[cards] = H9652;
Packit 427e91
		alsa_index[cards] = card;
Packit 427e91
		cards++;
Packit 427e91
	    } else if (!strncmp(name, "RME Hammerfall HDSP 9632", 24)) {
Packit 427e91
		printf("HDSP 9632 found !\n");
Packit 427e91
		hdsp_cards[cards] = H9632;
Packit 427e91
		alsa_index[cards] = card;
Packit 427e91
		cards++;	
Packit 427e91
	    } else if (!strncmp(name, "RME Hammerfall DSP", 18)) {
Packit 427e91
		printf("Uninitialized HDSP card found.\nUse hdsploader to upload configuration data to the card.\n");
Packit 427e91
	    }
Packit 427e91
            free(name);
Packit 427e91
	}
Packit 427e91
    }
Packit 427e91
#endif
Packit 427e91
    if (!cards) {
Packit 427e91
	printf("No Hammerfall DSP card found.\n");
Packit 427e91
	exit(1);
Packit 427e91
    }
Packit 427e91
    printf("%d Hammerfall DSP %s found.\n", cards, (cards > 1) ? "cards" : "card");
Packit 427e91
    
Packit 427e91
    window = new Fl_Window(WINDOW_WIDTH, WINDOW_HEIGHT, "Hammerfall DSP Alsa Settings");
Packit 427e91
    tabs = new Fl_Tabs(TABS_X, TABS_Y, TABS_W, TABS_H);
Packit 427e91
    window->end();
Packit 427e91
    for (int i = 0; i < cards; ++i) {
Packit 427e91
	    card_panes[i] = new HC_CardPane(alsa_index[i], i, hdsp_cards[i]);
Packit 427e91
	    tabs->add((Fl_Group *)card_panes[i]);
Packit 427e91
    }
Packit 427e91
    about_pane = new Fl_Group(10, 30, 480, 360, "About");
Packit 427e91
    about_pane->labelsize(10);
Packit 427e91
    about_text = new HC_AboutText(80, 70, 440, 210); 
Packit 427e91
    rme_logo = new HC_XpmRenderer(60, 328, 113, 35, rme_xpm);
Packit 427e91
    alsa_logo = new HC_XpmRenderer(230, 320, 50, 50, alsalogo_xpm);
Packit 427e91
    lad_banner = new HC_XpmRenderer(325, 325, 113, 39, lad_banner_xpm);
Packit 427e91
    about_pane->end();
Packit 427e91
    tabs->add(about_pane);
Packit 427e91
#ifndef GUI_TEST
Packit 427e91
    refresh_cb((void *)tabs);
Packit 427e91
#endif
Packit 427e91
    window->show(argc, argv);
Packit 427e91
    return Fl::run();    
Packit 427e91
}
Packit 427e91