Skip to content

Commit bcffdba

Browse files
lirc: Minor cleanups
1 parent 3081766 commit bcffdba

1 file changed

Lines changed: 66 additions & 89 deletions

File tree

src/lirc/lirc.cc

Lines changed: 66 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,43 @@
1-
/* Audacious LIRC plugin - lirc.c
1+
/*
2+
* LIRC plugin for Audacious
3+
* Copyright (c) 1998-1999 Carl van Schaik (carl@leg.uct.ac.za)
4+
* Copyright (C) 2000 Christoph Bartelmus (xmms@bartelmus.de)
5+
* Copyright (C) 2005 Audacious development team
6+
* Copyright (C) 2012 Joonas Harjumäki (jharjuma@gmail.com)
7+
*
8+
* Some code was taken from:
9+
* IRman plugin for XMMS by Charles Sielski (stray@teklabs.net)
10+
*
11+
* This program is free software; you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation; either version 2 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24+
*/
225

3-
Copyright (C) 2012 Joonas Harjumäki (jharjuma@gmail.com)
4-
5-
Copyright (C) 2005 Audacious development team
6-
7-
Copyright (c) 1998-1999 Carl van Schaik (carl@leg.uct.ac.za)
8-
9-
Copyright (C) 2000 Christoph Bartelmus (xmms@bartelmus.de)
10-
11-
some code was stolen from:
12-
IRman plugin for xmms by Charles Sielski (stray@teklabs.net)
13-
14-
This program is free software; you can redistribute it and/or modify
15-
it under the terms of the GNU General Public License as published by
16-
the Free Software Foundation; either version 2 of the License, or
17-
(at your option) any later version.
18-
19-
This program is distributed in the hope that it will be useful,
20-
but WITHOUT ANY WARRANTY; without even the implied warranty of
21-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22-
GNU General Public License for more details.
23-
24-
You should have received a copy of the GNU General Public License
25-
along with this program; if not, write to the Free Software
26-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27-
*/
28-
29-
#include <unistd.h>
3026
#include <fcntl.h>
31-
#include <string.h>
3227
#include <stdlib.h>
28+
#include <string.h>
29+
#include <unistd.h>
3330

3431
#include <glib.h>
3532
#include <lirc/lirc_client.h>
3633

3734
#include <libaudcore/drct.h>
35+
#include <libaudcore/hook.h>
3836
#include <libaudcore/i18n.h>
39-
#include <libaudcore/runtime.h>
4037
#include <libaudcore/playlist.h>
4138
#include <libaudcore/plugin.h>
4239
#include <libaudcore/preferences.h>
43-
#include <libaudcore/hook.h>
40+
#include <libaudcore/runtime.h>
4441

4542
class LIRCPlugin : public GeneralPlugin
4643
{
@@ -68,44 +65,39 @@ EXPORT LIRCPlugin aud_plugin_instance;
6865
static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition, void * data);
6966

7067
const char * const LIRCPlugin::defaults[] = {
71-
"enable_reconnect", "TRUE",
72-
"reconnect_timeout", "5",
73-
nullptr};
74-
75-
int lirc_fd = -1;
76-
struct lirc_config *config = nullptr;
77-
int tracknr = 0;
78-
int mute = 0; /* mute flag */
79-
int mute_vol = 0; /* holds volume before mute */
80-
81-
unsigned input_tag;
68+
"enable_reconnect", "TRUE",
69+
"reconnect_timeout", "5",
70+
nullptr
71+
};
8272

83-
char track_no[64];
84-
int track_no_pos;
85-
int tid;
73+
static int lirc_fd = -1;
74+
static struct lirc_config * config = nullptr;
75+
static bool muted = false; /* mute flag */
76+
static int mute_vol = 0; /* holds volume before mute */
77+
static unsigned input_tag;
78+
static char track_no[64];
79+
static int track_no_pos;
80+
static unsigned tid;
8681

87-
void init_lirc ()
82+
static void init_lirc ()
8883
{
89-
int flags;
90-
9184
if ((lirc_fd = lirc_init ((char *) "audacious", 1)) == -1)
9285
{
9386
AUDERR ("could not init LIRC support\n");
9487
return;
9588
}
96-
if (lirc_readconfig (nullptr, &config, nullptr) == -1)
89+
90+
if (lirc_readconfig (nullptr, & config, nullptr) == -1)
9791
{
9892
lirc_deinit ();
9993
AUDERR ("could not read LIRC config file\n");
10094
return;
10195
}
10296

10397
fcntl (lirc_fd, F_SETOWN, getpid ());
104-
flags = fcntl (lirc_fd, F_GETFL, 0);
98+
int flags = fcntl (lirc_fd, F_GETFL, 0);
10599
if (flags != -1)
106-
{
107100
fcntl (lirc_fd, F_SETFL, flags | O_NONBLOCK);
108-
}
109101

110102
GIOChannel * channel = g_io_channel_unix_new (lirc_fd);
111103
input_tag = g_io_add_watch (channel, G_IO_IN, lirc_input_callback, nullptr);
@@ -121,7 +113,7 @@ bool LIRCPlugin::init ()
121113
return true;
122114
}
123115

124-
gboolean reconnect_lirc (void * data)
116+
static gboolean reconnect_lirc (void * data)
125117
{
126118
AUDERR ("trying to reconnect...\n");
127119
aud_plugin_instance.init ();
@@ -140,14 +132,15 @@ void LIRCPlugin::cleanup ()
140132

141133
config = nullptr;
142134
}
135+
143136
if (lirc_fd != -1)
144137
{
145138
lirc_deinit ();
146139
lirc_fd = -1;
147140
}
148141
}
149142

150-
gboolean jump_to (void * data)
143+
static gboolean jump_to (void * data)
151144
{
152145
auto playlist = Playlist::active_playlist ();
153146
playlist.set_position (atoi (track_no) - 1);
@@ -158,21 +151,12 @@ gboolean jump_to (void * data)
158151

159152
static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition, void * data)
160153
{
161-
char *code;
162-
char *c;
163-
int output_time, v;
164-
int ret;
165-
char *ptr;
166-
int balance;
167-
#if 0
168-
gboolean show_pl;
169-
#endif
170-
int n;
171-
char *utf8_title_markup;
172-
173-
while ((ret = lirc_nextcode (&code)) == 0 && code != nullptr)
154+
char * code, * c, * ptr;
155+
int ret, n;
156+
157+
while ((ret = lirc_nextcode (& code)) == 0 && code != nullptr)
174158
{
175-
while ((ret = lirc_code2char (config, code, &c)) == 0 && c != nullptr)
159+
while ((ret = lirc_code2char (config, code, & c)) == 0 && c != nullptr)
176160
{
177161
if (g_ascii_strcasecmp ("PLAY", c) == 0)
178162
aud_drct_play ();
@@ -192,9 +176,7 @@ static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition
192176
if (n <= 0)
193177
n = 1;
194178
for (; n > 0; n--)
195-
{
196179
aud_drct_pl_next ();
197-
}
198180
}
199181
else if (g_ascii_strncasecmp ("PREV", c, 4) == 0)
200182
{
@@ -206,9 +188,7 @@ static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition
206188
if (n <= 0)
207189
n = 1;
208190
for (; n > 0; n--)
209-
{
210191
aud_drct_pl_prev ();
211-
}
212192
}
213193
else if (g_ascii_strcasecmp ("SHUFFLE", c) == 0)
214194
aud_toggle_bool ("shuffle");
@@ -223,7 +203,7 @@ static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition
223203

224204
if (n <= 0)
225205
n = 5000;
226-
output_time = aud_drct_get_time ();
206+
int output_time = aud_drct_get_time ();
227207
aud_drct_seek (output_time + n);
228208
}
229209
else if (g_ascii_strncasecmp ("BWD", c, 3) == 0)
@@ -235,7 +215,7 @@ static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition
235215

236216
if (n <= 0)
237217
n = 5000;
238-
output_time = aud_drct_get_time ();
218+
int output_time = aud_drct_get_time ();
239219
aud_drct_seek (output_time - n);
240220
}
241221
else if (g_ascii_strncasecmp ("VOL_UP", c, 6) == 0)
@@ -247,7 +227,7 @@ static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition
247227
if (n <= 0)
248228
n = 5;
249229

250-
v = aud_drct_get_volume_main ();
230+
int v = aud_drct_get_volume_main ();
251231
if (v > (100 - n))
252232
v = 100 - n;
253233
aud_drct_set_volume_main (v + n);
@@ -261,7 +241,7 @@ static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition
261241
if (n <= 0)
262242
n = 5;
263243

264-
v = aud_drct_get_volume_main ();
244+
int v = aud_drct_get_volume_main ();
265245
if (v < n)
266246
v = n;
267247
aud_drct_set_volume_main (v - n);
@@ -272,17 +252,17 @@ static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition
272252
}
273253
else if (g_ascii_strcasecmp ("MUTE", c) == 0)
274254
{
275-
if (mute == 0)
255+
if (! muted)
276256
{
277-
mute = 1;
278257
/* store the master volume so
279258
we can restore it on unmute. */
259+
muted = true;
280260
mute_vol = aud_drct_get_volume_main ();
281261
aud_drct_set_volume_main (0);
282262
}
283263
else
284264
{
285-
mute = 0;
265+
muted = false;
286266
aud_drct_set_volume_main (mute_vol);
287267
}
288268
}
@@ -295,7 +275,7 @@ static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition
295275
if (n <= 0)
296276
n = 5;
297277

298-
balance = aud_drct_get_volume_balance ();
278+
int balance = aud_drct_get_volume_balance ();
299279
balance -= n;
300280
if (balance < -100)
301281
balance = -100;
@@ -310,24 +290,19 @@ static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition
310290
if (n <= 0)
311291
n = 5;
312292

313-
balance = aud_drct_get_volume_balance ();
293+
int balance = aud_drct_get_volume_balance ();
314294
balance += n;
315295
if (balance > 100)
316296
balance = 100;
317297
aud_drct_set_volume_balance (balance);
318298
}
319299
else if (g_ascii_strcasecmp ("BAL_CENTER", c) == 0)
320300
{
321-
balance = 0;
322-
aud_drct_set_volume_balance (balance);
301+
aud_drct_set_volume_balance (0);
323302
}
324303
else if (g_ascii_strcasecmp ("LIST", c) == 0)
325304
{
326-
#if 0
327-
show_pl = aud_drct_pl_win_is_visible ();
328-
show_pl = (show_pl) ? 0 : 1;
329-
aud_drct_pl_win_toggle (show_pl);
330-
#endif
305+
// TODO: Toggle playlist visibility
331306
}
332307
else if (g_ascii_strcasecmp ("PLAYLIST_CLEAR", c) == 0)
333308
{
@@ -347,7 +322,7 @@ static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition
347322
track_no[track_no_pos++] = *c;
348323
track_no[track_no_pos] = 0;
349324
tid = g_timeout_add (1500, jump_to, nullptr);
350-
utf8_title_markup = g_markup_printf_escaped ("%s", track_no);
325+
char * utf8_title_markup = g_markup_printf_escaped ("%s", track_no);
351326
hook_call ("aosd toggle", utf8_title_markup);
352327
g_free (utf8_title_markup);
353328
}
@@ -357,10 +332,12 @@ static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition
357332
AUDERR ("unknown command \"%s\"\n", c);
358333
}
359334
}
335+
360336
g_free (code);
361337
if (ret == -1)
362338
break;
363339
}
340+
364341
if (ret == -1)
365342
{
366343
/* something went badly wrong */

0 commit comments

Comments
 (0)