Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
panelcontrol
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
minus
panelcontrol
Commits
982e8f97
Commit
982e8f97
authored
Sep 09, 2019
by
minus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move ALSA code to separate file
parent
b5a7f0ec
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
76 deletions
+93
-76
alsa.c
alsa.c
+74
-0
alsa.h
alsa.h
+3
-0
meson.build
meson.build
+1
-1
panelcontrol.c
panelcontrol.c
+15
-75
No files found.
alsa.c
0 → 100644
View file @
982e8f97
#include <glib.h>
#include "panelcontrol.h"
#include "alsa.h"
static
gboolean
on_alsa_readable
(
GIOChannel
*
source
,
GIOCondition
condition
,
gpointer
data
)
{
fprintf
(
stdout
,
"source=%p cond=%i data=%p
\n
"
,
(
void
*
)
source
,
condition
,
data
);
snd_seq_t
*
seq
=
(
snd_seq_t
*
)
data
;
snd_seq_event_t
*
ev
;
while
(
1
)
{
int
remaining
=
snd_seq_event_input
(
seq
,
&
ev
);
if
(
remaining
==
-
EAGAIN
)
{
return
TRUE
;
}
else
if
(
remaining
<
0
)
{
perror
(
"Error reading sequencer input"
);
}
switch
(
ev
->
type
)
{
case
SND_SEQ_EVENT_NOTEON
:
fprintf
(
stdout
,
"button %i: %i
\n
"
,
ev
->
data
.
note
.
note
,
ev
->
data
.
note
.
velocity
>
0
);
snd_seq_ev_set_subs
(
ev
);
snd_seq_ev_set_direct
(
ev
);
snd_seq_event_output_direct
(
seq
,
ev
);
break
;
case
SND_SEQ_EVENT_CONTROLLER
:
fprintf
(
stdout
,
"knob %i: %i
\n
"
,
ev
->
data
.
control
.
param
,
ev
->
data
.
control
.
value
);
break
;
}
snd_seq_free_event
(
ev
);
}
return
TRUE
;
}
static
int
port
;
void
alsa
(
int
source
,
snd_seq_t
**
seq_ret
,
int
*
port_ret
)
{
// connect to ALSA seq
snd_seq_t
*
seq
;
if
(
snd_seq_open
(
&
seq
,
"hw"
,
SND_SEQ_OPEN_DUPLEX
,
SND_SEQ_NONBLOCK
)
<
0
)
{
fprintf
(
stderr
,
"Error opening ALSA sequencer.
\n
"
);
exit
(
1
);
}
if
(
seq_ret
)
*
seq_ret
=
seq
;
snd_seq_set_client_name
(
seq
,
CLIENT_NAME
);
int
port
=
snd_seq_create_simple_port
(
seq
,
CLIENT_NAME
,
SND_SEQ_PORT_CAP_WRITE
|
SND_SEQ_PORT_CAP_SUBS_WRITE
|
SND_SEQ_PORT_CAP_READ
|
SND_SEQ_PORT_CAP_SUBS_READ
,
SND_SEQ_PORT_TYPE_APPLICATION
);
if
(
port
<
0
)
{
fprintf
(
stderr
,
"Error creating sequencer port.
\n
"
);
exit
(
1
);
}
if
(
port_ret
)
*
port_ret
=
port
;
// read from and write to panel device
snd_seq_connect_from
(
seq
,
port
,
source
,
0
);
snd_seq_connect_to
(
seq
,
port
,
source
,
0
);
// event loop
int
npfd
;
struct
pollfd
*
pfd
;
npfd
=
snd_seq_poll_descriptors_count
(
seq
,
POLLIN
);
pfd
=
(
struct
pollfd
*
)
alloca
(
npfd
*
sizeof
(
struct
pollfd
));
snd_seq_poll_descriptors
(
seq
,
pfd
,
npfd
,
POLLIN
);
for
(
int
i
=
0
;
i
<
npfd
;
++
i
)
{
GIOChannel
*
ch
=
g_io_channel_unix_new
(
pfd
[
i
].
fd
);
guint
evsrcid
=
g_io_add_watch
(
ch
,
pfd
[
i
].
events
,
&
on_alsa_readable
,
seq
);
}
}
alsa.h
0 → 100644
View file @
982e8f97
#include <alsa/asoundlib.h>
void
alsa
(
int
source
,
snd_seq_t
**
seq_ret
,
int
*
port_ret
);
meson.build
View file @
982e8f97
...
...
@@ -9,7 +9,7 @@ alsa = dependency('alsa')
glib = dependency('glib-2.0')
executable('panelcontrol',
['panelcontrol.c', 'pa.c', 'pa_sink_input_watch_list.c'],
['panelcontrol.c', '
alsa.c', '
pa.c', 'pa_sink_input_watch_list.c'],
dependencies : [pa, alsa, glib],
install : true)
...
...
panelcontrol.c
View file @
982e8f97
...
...
@@ -4,78 +4,10 @@
#include <glib.h>
#include "panelcontrol.h"
#include "alsa.h"
#include "pa.h"
#include "pa_sink_input_watch_list.h"
gboolean
on_alsa_readable
(
GIOChannel
*
source
,
GIOCondition
condition
,
gpointer
data
)
{
fprintf
(
stdout
,
"source=%p cond=%i data=%p
\n
"
,
(
void
*
)
source
,
condition
,
data
);
snd_seq_t
*
seq
=
(
snd_seq_t
*
)
data
;
snd_seq_event_t
*
ev
;
while
(
1
)
{
int
remaining
=
snd_seq_event_input
(
seq
,
&
ev
);
if
(
remaining
==
-
EAGAIN
)
{
return
TRUE
;
}
else
if
(
remaining
<
0
)
{
perror
(
"Error reading sequencer input"
);
}
switch
(
ev
->
type
)
{
case
SND_SEQ_EVENT_NOTEON
:
fprintf
(
stdout
,
"button %i: %i
\n
"
,
ev
->
data
.
note
.
note
,
ev
->
data
.
note
.
velocity
>
0
);
snd_seq_ev_set_subs
(
ev
);
snd_seq_ev_set_direct
(
ev
);
snd_seq_event_output_direct
(
seq
,
ev
);
break
;
case
SND_SEQ_EVENT_CONTROLLER
:
fprintf
(
stdout
,
"knob %i: %i
\n
"
,
ev
->
data
.
control
.
param
,
ev
->
data
.
control
.
value
);
break
;
}
snd_seq_free_event
(
ev
);
}
return
TRUE
;
}
static
int
port
;
snd_seq_t
*
alsa
(
int
source
)
{
// connect to ALSA seq
snd_seq_t
*
seq
;
if
(
snd_seq_open
(
&
seq
,
"hw"
,
SND_SEQ_OPEN_DUPLEX
,
SND_SEQ_NONBLOCK
)
<
0
)
{
fprintf
(
stderr
,
"Error opening ALSA sequencer.
\n
"
);
exit
(
1
);
}
snd_seq_set_client_name
(
seq
,
CLIENT_NAME
);
port
=
snd_seq_create_simple_port
(
seq
,
CLIENT_NAME
,
SND_SEQ_PORT_CAP_WRITE
|
SND_SEQ_PORT_CAP_SUBS_WRITE
|
SND_SEQ_PORT_CAP_READ
|
SND_SEQ_PORT_CAP_SUBS_READ
,
SND_SEQ_PORT_TYPE_APPLICATION
);
if
(
port
<
0
)
{
fprintf
(
stderr
,
"Error creating sequencer port.
\n
"
);
exit
(
1
);
}
// read from and write to panel device
snd_seq_connect_from
(
seq
,
port
,
source
,
0
);
snd_seq_connect_to
(
seq
,
port
,
source
,
0
);
// event loop
int
npfd
;
struct
pollfd
*
pfd
;
npfd
=
snd_seq_poll_descriptors_count
(
seq
,
POLLIN
);
pfd
=
(
struct
pollfd
*
)
alloca
(
npfd
*
sizeof
(
struct
pollfd
));
snd_seq_poll_descriptors
(
seq
,
pfd
,
npfd
,
POLLIN
);
for
(
int
i
=
0
;
i
<
npfd
;
++
i
)
{
GIOChannel
*
ch
=
g_io_channel_unix_new
(
pfd
[
i
].
fd
);
guint
evsrcid
=
g_io_add_watch
(
ch
,
pfd
[
i
].
events
,
&
on_alsa_readable
,
seq
);
}
return
seq
;
}
//void toggle_mute(enum button button, void *userdata) {
// const char *name = (const char *)userdata;
...
...
@@ -106,7 +38,14 @@ snd_seq_t *alsa(int source) {
//static const struct encoder_map_entry encoder_map[] = {
// {.encoder = ENC1, .sink_input = NULL, .action = &change_volume},
//};
void
midi_button_led
(
snd_seq_t
*
seq
,
enum
button
button
,
enum
button_led_state
state
)
{
struct
seq_port
{
snd_seq_t
*
seq
;
int
port
;
};
void
midi_button_led
(
snd_seq_t
*
seq
,
int
port
,
enum
button
button
,
enum
button_led_state
state
)
{
snd_seq_event_t
ev
;
snd_seq_ev_clear
(
&
ev
);
snd_seq_ev_set_source
(
&
ev
,
port
);
...
...
@@ -117,13 +56,13 @@ void midi_button_led(snd_seq_t *seq, enum button button, enum button_led_state s
}
void
show_mute_and_speakers
(
struct
sink_input_watch
*
w
)
{
s
nd_seq_t
*
seq
=
w
->
userdata
;
midi_button_led
(
s
eq
,
TOP1
,
w
->
mute
?
BUTTON_LED_ON
:
BUTTON_LED_OFF
);
s
truct
seq_port
*
sp
=
w
->
userdata
;
midi_button_led
(
s
p
->
seq
,
sp
->
port
,
TOP1
,
w
->
mute
?
BUTTON_LED_ON
:
BUTTON_LED_OFF
);
uint32_t
speakers
=
3
;
uint32_t
headphones
=
4
;
midi_button_led
(
s
eq
,
BOTTOM1
,
w
->
sink
==
speakers
?
BUTTON_LED_ON
:
BUTTON_LED_OFF
);
midi_button_led
(
s
p
->
seq
,
sp
->
port
,
BOTTOM1
,
w
->
sink
==
speakers
?
BUTTON_LED_ON
:
BUTTON_LED_OFF
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -133,10 +72,11 @@ int main(int argc, char *argv[]) {
}
int
source
=
atoi
(
argv
[
1
]);
snd_seq_t
*
seq
=
alsa
(
source
);
struct
seq_port
sp
;
alsa
(
source
,
&
sp
.
seq
,
&
sp
.
port
);
struct
sink_input_watch
*
mpd
=
sink_inputs_add_sink
(
"mpd pulse"
);
mpd
->
userdata
=
seq
;
mpd
->
userdata
=
&
sp
;
mpd
->
volume_changed
=
show_mute_and_speakers
;
pa
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment