jack_server_control.cpp 5.57 KB
Newer Older
sletz's avatar
sletz committed
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
/*
 	Copyright (C) 2008 Grame
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <jack/jack.h>
#include <jack/control.h>

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
static jackctl_driver_t * jackctl_server_get_driver(jackctl_server_t *server, const char *driver_name)
{
    const JSList * node_ptr = jackctl_server_get_drivers_list(server);

    while (node_ptr) {
        if (strcmp(jackctl_driver_get_name((jackctl_driver_t *)node_ptr->data), driver_name) == 0) {
            return (jackctl_driver_t *)node_ptr->data;
        }
        node_ptr = jack_slist_next(node_ptr);
    }

    return NULL;
}

static jackctl_internal_t * jackctl_server_get_internal(jackctl_server_t *server, const char *internal_name)
{
    const JSList * node_ptr = jackctl_server_get_internals_list(server);

    while (node_ptr) {
        if (strcmp(jackctl_internal_get_name((jackctl_internal_t *)node_ptr->data), internal_name) == 0) {
            return (jackctl_internal_t *)node_ptr->data;
        }
        node_ptr = jack_slist_next(node_ptr);
    }

    return NULL;
}
sletz's avatar
sletz committed
55

sletz's avatar
sletz committed
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
static void print_value(union jackctl_parameter_value value, jackctl_param_type_t type)
{
    switch (type) {
    
        case JackParamInt:
            printf("parameter value = %d\n", value.i);
            break;
            
         case JackParamUInt:
            printf("parameter value = %u\n", value.ui);
            break;
            
         case JackParamChar:
            printf("parameter value = %c\n", value.c);
            break;
        
         case JackParamString:
            printf("parameter value = %s\n", value.str);
            break;
            
         case JackParamBool:
            printf("parameter value = %d\n", value.b);
            break;
     }
}

static void print_parameters(const JSList * node_ptr)
{
    while (node_ptr != NULL) {
        jackctl_parameter_t * parameter = (jackctl_parameter_t *)node_ptr->data;
        printf("\nparameter name = %s\n", jackctl_parameter_get_name(parameter));
        printf("parameter id = %c\n", jackctl_parameter_get_id(parameter));
        printf("parameter short decs = %s\n", jackctl_parameter_get_short_description(parameter));
        printf("parameter long decs = %s\n", jackctl_parameter_get_long_description(parameter));
        print_value(jackctl_parameter_get_default_value(parameter), jackctl_parameter_get_type(parameter));
        node_ptr = jack_slist_next(node_ptr);
    }
}

static void print_driver(jackctl_driver_t * driver)
{
    printf("\n--------------------------\n");
    printf("driver = %s\n", jackctl_driver_get_name(driver));
    printf("-------------------------- \n");
    print_parameters(jackctl_driver_get_parameters(driver)); 
}

static void print_internal(jackctl_internal_t * internal)
{
    printf("\n-------------------------- \n");
    printf("internal = %s\n", jackctl_internal_get_name(internal));
    printf("-------------------------- \n");
    print_parameters(jackctl_internal_get_parameters(internal));
}

sletz's avatar
sletz committed
111
112
113
114
115
116
117
118
119
static void usage()
{
	fprintf (stderr, "\n"
					"usage: jack_server_control \n"
					"              [ --driver OR -d driver_name ]\n"
					"              [ --client OR -c client_name ]\n"
	);
}

sletz's avatar
sletz committed
120
121
int main(int argc, char *argv[])
{
122
    jackctl_server_t * server;
sletz's avatar
sletz committed
123
124
125
    const JSList * drivers;
    const JSList * internals;
    const JSList * node_ptr;
126
    sigset_t signals;
sletz's avatar
sletz committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
    int opt, option_index;
    char* driver_name = "dummy";
    char* client_name = "audioadapter";

    const char *options = "d:c:";
	struct option long_options[] = {
		{"driver", 1, 0, 'd'},
		{"client", 1, 0, 'c'},
	};
    
 	while ((opt = getopt_long (argc, argv, options, long_options, &option_index)) != EOF) {
		switch (opt) {
			case 'd':
				driver_name = optarg;
				break;
			case 'c':
				client_name = optarg;
				break;
            default:
				usage();
                exit(0);
		}
	}
    
sletz's avatar
sletz committed
151
152
	server = jackctl_server_create();
    
sletz's avatar
sletz committed
153
154
155
156
    printf("\n========================== \n");
    printf("List of drivers \n");
    printf("========================== \n");
    
sletz's avatar
sletz committed
157
158
159
    drivers = jackctl_server_get_drivers_list(server);
    node_ptr = drivers;
    while (node_ptr != NULL) {
sletz's avatar
sletz committed
160
        print_driver((jackctl_driver_t *)node_ptr->data);
sletz's avatar
sletz committed
161
162
163
        node_ptr = jack_slist_next(node_ptr);
    }
    
sletz's avatar
sletz committed
164
165
166
167
    printf("\n========================== \n");
    printf("List of internal clients \n");
    printf("========================== \n");
    
sletz's avatar
sletz committed
168
169
170
    internals = jackctl_server_get_internals_list(server);
    node_ptr = internals;
    while (node_ptr != NULL) {
sletz's avatar
sletz committed
171
        print_internal((jackctl_internal_t *)node_ptr->data);
sletz's avatar
sletz committed
172
173
174
        node_ptr = jack_slist_next(node_ptr);
    }
    
sletz's avatar
sletz committed
175
176
    jackctl_server_start(server, jackctl_server_get_driver(server, driver_name));
    jackctl_server_load_internal(server, jackctl_server_get_internal(server, client_name));
177
178
179
180
     
    signals = jackctl_setup_signals(0);
    jackctl_wait_signals(signals);
     
sletz's avatar
sletz committed
181
182
183
    jackctl_server_destroy(server);
    return 0;
}