1 /*
2 * handlers_equalizer.c
3 * Copyright 2007-2013 Yoshiki Yazawa, Matti Hämäläinen, and John Lindgren
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions, and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions, and the following disclaimer in the documentation
13 * provided with the distribution.
14 *
15 * This software is provided "as is" and without any warranty, express or
16 * implied. In no event shall the authors be liable for any damages arising from
17 * the use of this software.
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22
23 #include "audtool.h"
24 #include "wrappers.h"
25
26 #define NUM_BANDS 10
27
equalizer_get_eq(int argc,char ** argv)28 void equalizer_get_eq (int argc, char * * argv)
29 {
30 double preamp = 0.0;
31 GVariant * var = NULL;
32
33 obj_audacious_call_get_eq_sync (dbus_proxy, & preamp, & var, NULL, NULL);
34
35 if (! var || ! g_variant_is_of_type (var, G_VARIANT_TYPE ("ad")))
36 exit (1);
37
38 audtool_report ("preamp = %.2f", preamp);
39
40 size_t nbands = 0;
41 const double * bands = g_variant_get_fixed_array (var, & nbands, sizeof (double));
42
43 if (nbands != NUM_BANDS)
44 exit (1);
45
46 for (int i = 0; i < NUM_BANDS; i ++)
47 printf ("%.2f ", bands[i]);
48
49 printf ("\n");
50 g_variant_unref (var);
51 }
52
equalizer_get_eq_preamp(int argc,char ** argv)53 void equalizer_get_eq_preamp (int argc, char * * argv)
54 {
55 double preamp = 0;
56 obj_audacious_call_get_eq_preamp_sync (dbus_proxy, & preamp, NULL, NULL);
57 audtool_report ("preamp = %.2f", preamp);
58 }
59
equalizer_get_eq_band(int argc,char ** argv)60 void equalizer_get_eq_band (int argc, char * * argv)
61 {
62 if (argc < 2)
63 {
64 audtool_whine_args (argv[0], "<band>");
65 exit (1);
66 }
67
68 int band = atoi (argv[1]);
69
70 double level = 0;
71 obj_audacious_call_get_eq_band_sync (dbus_proxy, band, & level, NULL, NULL);
72 audtool_report ("band %d = %.2f", band, level);
73 }
74
equalizer_set_eq(int argc,char ** argv)75 void equalizer_set_eq (int argc, char * * argv)
76 {
77 if (argc < 2 + NUM_BANDS)
78 {
79 audtool_whine_args (argv[0], "<preamp> <band0> <band1> <band2> <band3> "
80 "<band4> <band5> <band6> <band7> <band8> <band9>");
81 exit (1);
82 }
83
84 double preamp = atof (argv[1]);
85 double bands[NUM_BANDS];
86
87 for (int i = 0; i < NUM_BANDS; i ++)
88 bands[i] = atof (argv[i + 2]);
89
90 GVariant * var = g_variant_new_fixed_array (G_VARIANT_TYPE_DOUBLE, bands,
91 NUM_BANDS, sizeof (double));
92 obj_audacious_call_set_eq_sync (dbus_proxy, preamp, var, NULL, NULL);
93 }
94
equalizer_set_eq_preamp(int argc,char ** argv)95 void equalizer_set_eq_preamp (int argc, char * * argv)
96 {
97 if (argc < 2)
98 {
99 audtool_whine_args (argv[0], "<preamp>");
100 exit (1);
101 }
102
103 double preamp = atof (argv[1]);
104 obj_audacious_call_set_eq_preamp_sync (dbus_proxy, preamp, NULL, NULL);
105 }
106
equalizer_set_eq_band(int argc,char ** argv)107 void equalizer_set_eq_band (int argc, char * * argv)
108 {
109 if (argc < 3)
110 {
111 audtool_whine_args (argv[0], "<band> <value>");
112 exit (1);
113 }
114
115 int band = atoi (argv[1]);
116 double level = atof (argv[2]);
117 obj_audacious_call_set_eq_band_sync (dbus_proxy, band, level, NULL, NULL);
118 }
119
equalizer_active(int argc,char ** argv)120 void equalizer_active (int argc, char * * argv)
121 {
122 generic_on_off (argc, argv, obj_audacious_call_equalizer_activate_sync);
123 }
124