Example #1
0
/**
 * Parse notes
 */
void note()
{
    struct note_t note;
    note_init(&note);

    note.note = get_note();
    note.octave = (int)abcNoteOctave(scn);

    /* Convert durations from ABC format to a simpler one (1/2^x) -> (1/x) */
    note.duration = (int)pow(2, abcNoteDuration(scn) + 1);
    note_write(&note);
}
Example #2
0
/**
 * Parse rests
 */
void rest()
{
    struct note_t note;

    note_init(&note);
    note.note = NOTE_REST;

    /* Convert durations from ABC format to a simpler one (1/2^x) -> (1/x) */
    note.duration = (int)pow(2, abcRestDuration(scn) + 1);
    note.octave = 0;
    note_write(&note);
}
Example #3
0
int main(int argc, char **argv)
{
    struct sigaction sa;
    struct tonegend tonegend;
    struct cmdopt cmdopt;

    cmdopt.daemon = 0;
    cmdopt.uid = -1;
    cmdopt.path = NULL;
    cmdopt.standard = STD_CEPT;
    cmdopt.interactive = 0;
    cmdopt.sample_rate = 48000;
    cmdopt.statistics = 0;
    cmdopt.buflen = 0;
    cmdopt.minreq = 0;
    cmdopt.dtmf_tags = NULL;
    cmdopt.ind_tags = NULL;
    cmdopt.notif_tags = NULL;
    cmdopt.dtmf_volume = 100;
    cmdopt.ind_volume = 100;
    cmdopt.notif_volume = 100;
    
    parse_options(argc, argv, &cmdopt);

    memset(&tonegend, 0, sizeof(tonegend));

    memset(&sa, 0, sizeof(sa));
    sa.sa_sigaction = signal_handler;
    sa.sa_flags = SA_SIGINFO;
    
    if (sigaction(SIGHUP , &sa, NULL) < 0 ||
        sigaction(SIGTERM, &sa, NULL) < 0 ||
        sigaction(SIGINT , &sa, NULL) < 0   ) {
        LOG_ERROR("Failed to install signal handlers");
        return errno;
    }

    if (dbusif_init(argc, argv)    < 0 ||
        ausrv_init(argc, argv)     < 0 ||
        stream_init(argc, argv)    < 0 ||
        tone_init(argc, argv)      < 0 ||
        envelop_init(argc, argv)   < 0 ||
        indicator_init(argc, argv) < 0 ||
        dtmf_init(argc, argv)      < 0 ||
        note_init(argc, argv)      < 0 ||
        interact_init(argc, argv)  < 0 ||
        rfc4733_init(argc, argv)   < 0 ||
        notif_init(argc, argv)     < 0) {
        LOG_ERROR("Error during initialization");
        return EINVAL;
    }


    stream_set_default_samplerate(cmdopt.sample_rate);
    stream_print_statistics(cmdopt.statistics);
    stream_buffering_parameters(cmdopt.buflen, cmdopt.minreq);

    dtmf_set_properties(cmdopt.dtmf_tags);
    indicator_set_properties(cmdopt.ind_tags);
    notif_set_properties(cmdopt.notif_tags);

    dtmf_set_volume(cmdopt.dtmf_volume);
    indicator_set_volume(cmdopt.ind_volume);
    notif_set_volume(cmdopt.notif_volume);

    if (cmdopt.daemon)
        daemonize(cmdopt.uid, cmdopt.path);

    if ((main_loop = g_main_loop_new(NULL, FALSE)) == NULL) {
        LOG_ERROR("Can't create main loop");
        return EIO;
    }
        
    if ((tonegend.dbus_ctx = dbusif_create(&tonegend)) == NULL) {
        LOG_ERROR("D-Bus setup failed");
        return EIO;
    }

    if ((tonegend.ausrv_ctx = ausrv_create(&tonegend,pa_server_name)) == NULL){
        LOG_ERROR("Pulse Audio setup failed");
        return EIO;
    }

    if (rfc4733_create(&tonegend) < 0) {
        LOG_ERROR("Can't setup rfc4733 interface on D-Bus");
        return EIO;
    }

    if (notif_create(&tonegend) < 0) {
        LOG_ERROR("Can't setup notification interface on D-Bus");
        return EIO;
    }

    if (!cmdopt.daemon && cmdopt.interactive) {
        if (!(tonegend.intact_ctx = interact_create(&tonegend,fileno(stdin)))){
            LOG_ERROR("Can't setup interactive console");
            return EIO;
        }
        printf("Running in interactive mode\n");
    }

    indicator_set_standard(cmdopt.standard);

    g_main_loop_run(main_loop);

    LOG_INFO("Exiting now ...");

    ausrv_destroy(tonegend.ausrv_ctx);
    dbusif_destroy(tonegend.dbus_ctx);
    interact_destroy(tonegend.intact_ctx);

    if (main_loop != NULL) 
        g_main_loop_unref(main_loop);

    ausrv_exit();

    return 0;
}