File: petri-foo.c

package info (click to toggle)
petri-foo 0.1.87-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,468 kB
  • ctags: 2,233
  • sloc: ansic: 18,946; xml: 7; makefile: 6
file content (162 lines) | stat: -rw-r--r-- 3,982 bytes parent folder | download | duplicates (2)
1
2
3
4
5
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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
/*  Petri-Foo is a fork of the Specimen audio sampler.

    Original Specimen author Pete Bessman
    Copyright 2005 Pete Bessman
    Copyright 2011 James W. Morris

    This file is part of Petri-Foo.

    Petri-Foo is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 2 as
    published by the Free Software Foundation.

    Petri-Foo 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 Petri-Foo.  If not, see <http://www.gnu.org/licenses/>.

    This file is a derivative of a Specimen original, modified 2011
*/

#include <getopt.h>
#include <gtk/gtk.h>
#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>

#include "dish_file.h"
#include "driver.h"
#include "global_settings.h"
#include "gui.h"
#include "instance.h"
#include "jackdriver.h"
#include "lfo.h"
#include "midi.h"
#include "mixer.h"
#include "mod_src.h"
#include "msg_log.h"
#include "names.h"
#include "patch.h"
#include "patch_util.h"
#include "petri-foo.h"
#include "session.h"


void show_usage (void)
{
    printf ("Usage: petri-foo [options] [bank]\n");
    printf("(Bank files use .petri-foo extension)\n\n");

    printf ("Options:\n");
    printf("  -a, --autoconnect         Auto-connect through JACK to "
                                        "system playback ports\n");
    printf("  -j, --jack-name <name>    Specify JACK client name, "
                                        "defaults to \"Petri-Foo\"\n" );
    printf("  -u, --unconnected         Don't auto-connect to JACK system "
                                        "playback ports (deprecated)\n");
    printf("  -U, --uuid <uuid>         Set UUID for JACK session\n");
    printf("  -h, --help                Display this help message\n\n");
    printf("For more information, please see:"
            "http://petri-foo.sourceforge.net/\n");
}


void cleanup(void)
{
    msg_log(MSG_MESSAGE, "Cleanup...\n");
    session_cleanup();
    dish_file_state_cleanup();
    midi_stop();
    driver_stop();
    patch_shutdown();
    mixer_shutdown();
    settings_write();
    settings_free();
    free_instance_name();
    mod_src_destroy();

    msg_log(MSG_MESSAGE, "Goodbye!\n");

    exit(0);
}


void sigint_handler()
{
    puts("\n");
    msg_log(MSG_MESSAGE, "Caught SIGINT signal\n");
    cleanup();
}

void sighup_handler()
{
    puts("\n");
    msg_log(MSG_MESSAGE, "Caught SIGHUP signal\n");
    cleanup();
}

void sigterm_handler()
{
    puts("\n");
    msg_log(MSG_MESSAGE, "Caught SIGTERM signal\n");
    cleanup();
}


int main(int argc, char *argv[])
{
    enum { SC = 3 };
    int opt, n;
    int sigs[] = { SIGINT, SIGHUP, SIGTERM };
    void (*sighandlers[])() = { sigint_handler,
                                sighup_handler,
                                sigterm_handler };
    struct sigaction s[SC];

    for (n = 0; n < SC; ++n)
    {
        s[n].sa_handler = SIG_IGN;
        sigfillset(&s[n].sa_mask);
        s[n].sa_flags = 0;
        sigaction(sigs[n], &s[n], NULL);
    }

    for (opt = 1; opt < argc; ++opt)
    {
        if (strcmp(argv[opt], "-h") == 0
         || strcmp(argv[opt], "--help") == 0)
        {
            show_usage();
            return 0;
        }
    }

    mod_src_create();
    gtk_init(&argc, &argv);
    settings_init();
    driver_init();
    lfo_tables_init();
    mixer_init();
    patch_control_init();
    dish_file_state_init();
    session_init(argc, argv);
    gui_init();

    for (n = 0; n < SC; ++n)
    {
        s[n].sa_handler = sighandlers[n];
        sigfillset(&s[n].sa_mask);
        s[n].sa_flags = 0;
        sigaction(sigs[n], &s[n], NULL);
    }

    gtk_main();

    cleanup();

    return 0;
}