Using system, or qx, or similar methods will block the Tk eventloop, although you may get away with it it for such short commands. To do it properly, you want to use the non-blocking IPC methods available to Tk's eventloop.
See
ztk-v4l-video-bloger/recorder for an example. I'm not sure if the amixer commands are still current with newer alsa versions, but it does show the method for using amixer with Tk. You can get a list of all alsamixer settings, just google for how.
The important part of the code above is this:
#setup a shell thru IPC to carry out different
# mixer and v4l2 control commands
my $pidcon = open3(\*CON,0,0,'/bin/sh');
# then later use it like this
&mic_con(1); #turn on Mic
sub mic_con{
my $con = shift;
if($con == 1){ #turn Mic on to max for recording
#turn off playback to avoid feedback squeal
print CON "amixer cset name='AC97 Playback Volume', 0\n";
#switch the capture to Mic
print CON "amixer sset Mic Capture cap\n";
#turn up maximum Mic gain
print CON "amixer cset name='Mic Playback Volume', 100\n";
#turn on Mic +20db boost
print CON "amixer cset name='Mic Boost (+20dB)', 1\n";
}
if($con == 0){ #restore old Line settings
#turn off Mic by changing capture to Line
print CON "amixer sset Line Capture cap\n";
#turn off Mic +20db boost
print CON "amixer cset name='Mic Boost (+20dB)', 0\n";
#restore normal capture volume
print CON "amixer cset name='AC97 Playback Volume', 88\n";
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.