Vous n'êtes pas identifié(e).

#1 2011-02-11 00:32:34

Kookaburra
#! /bin/modo
Inscription : 2010-09-26
Messages : 871
Site Web

MoC : tout pour bien le contrôler !

Voilà ce que j'ai réalisé pour contrôler efficacement MoC (= Music On Console, application qui va parfaitement à l'esprit "#!" je trouve) avec Openbox :


* Pipe-Menu :

#!/bin/sh
# moc-ob-pipe - control moc in your openbox menu
# chmod +x mmoc-ob-pipe.sh, and place:
# "<menu id="pipe-moc-menu" label="MMusicOnConsole Pipe" execute="/path/to/script/moc-ob-pipe.sh" />"
# somewhere in your menu.

#set variables
playing=`mocp --info | egrep "^Artist\:|^SongTitle\:|^Album\:" | sed -n 'p'`
nowstatus=`mocp --info | sed -n '1p' | cut -c 8-15`
 
# convert reserved XML characters '&', '<', '>', '"' for songs containing characters

if [[ $playing =~ '&' ]]
then
export playing=${playing//\&/\&amp\;}
fi
 
if [[ $playing =~ '<' ]]
then
export playing=${playing//\</\&lt\;}
fi
 
if [[ $playing =~ '>' ]]
then
export playing=${playing//\>/\&gt\;}
fi
 
if [[ $playing =~ '"' ]]
then
export playing=${playing//\"/\&quot\;}
fi
 
# echo menu
 
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
echo "<openbox_pipe_menu>"
echo " <menu id=\"MoC-playing\" label=\"$nowstatus\">"
echo " <item label=\"$playing\">"
echo " <action name=\"Execute\"><execute>mocp --toggle-pause</execute></action>"
echo " </item>"
echo " </menu>"
echo " <separator />"
echo " <item label=\"play/pause\">"
echo " <action name=\"Execute\"><execute>mocp --toggle-pause</execute></action>"
echo " </item>"
echo " <item label=\"prev\">"
echo " <action name=\"Execute\"><execute>mocp --previous</execute></action>"
echo " </item>"
echo " <item label=\"next\">"
echo " <action name=\"Execute\"><execute>mocp --next</execute></action>"
echo " </item>"
echo " <item label=\"stop\">"
echo " <action name=\"Execute\"><execute>mocp --stop</execute></action>"
echo " </item>"
echo "</openbox_pipe_menu>"

NINbD.png

* Fichier de configuration :

# This is a configuration file for the MOC player. It should be named 'config'
# and placed in the directory ~/.moc/
# Comments begin with '#'.
# You can use quotes and escape ('\') in parameters.

# Music Directory.
MusicDir = "/home/Stockage/Musique"

# Show file titles (title, author, album) instead of file names.
ReadTags        = yes

# Directory in which you store music files. If you specify it you will be able
# to quickly go to this directory with the '-m' parameter or the 'm' command.
# This can also point to a playlist.
#MusicDir        = "/home/joe/music"

# How to sort? FileName is the only option for now.
Sort            = FileName

# Show errors in the streams, for example CRC errors or broken frames in mp3
# files.
ShowStreamErrors    = no

# Ignore CRC errors in MP3 files. Most players do that, so the default value is
# set to yes.
Mp3IgnoreCRCErrors    = yes

# Turn on repeat.
Repeat            = no

# Turn on shuffle.
Shuffle            = yes

# Turn on AutoNext.
AutoNext        = yes

# Default FormatString:
# %n - Track number
# %a - Artist
# %A - Album
# %t - Title
# %(X:TRUE:FALSE) - ternary expression - if X exists, do TRUE, otherwise
#                   FALSE. '\' - escape character (must be double, because of 
#                   config interpreter). man zshmisc for more info.
FormatString        = "%(n:%n :)%(a:%a - :)%(t:%t:)%(A: \(%A\):)"

# Output buffer size in kilobytes. Minimum value is 128KB. */
OutputBuffer        = 2048

# Input buffer size in kilobytes. Minimum value is 32KB. */
InputBuffer        = 512

# How much to fill the input buffer before playing (in kilobytes)?
# This can't be more than InputBuffer value.
# Remember that for network streams beside the positive effect this also causes
# delay between what you can hear and what is broadcasted.
Prebuffering        = 64

# Use this HTTP proxy server for internet streams. If not set, the
# environment variables http_proxy and ALL_PROXY will be used if present.
#HTTPProxy        = my_proxy:port

# Sound driver - OSS, ALSA, JACK, or null (only for debugging).
# You can enter more than one driver separated by a comma. The first working
# driver will be used.
SoundDriver        = JACK, ALSA, OSS

# Jack output settings.
JackOutLeft        = "alsa_pcm:playback_1"
JackOutRight    = "alsa_pcm:playback_2"

# OSS output device.
OSSDevice        = /dev/dsp

# OSS Mixer device.
OSSMixerDevice        = /dev/mixer

# OSS Mixer channel: pcm or master.
OSSMixerChannel        = pcm

# Second OSS Mixer channel: pcm or master.
OSSMixerChannel2    = master

# ALSA mixer device.
AlsaMixer         = PCM

# Second ALSA mixer device.
AlsaMixer2        = Master

# ALSA output device.
AlsaDevice        = default

# Save software mixer state?
# If enabled, a file 'softmixer' will
# be created in '~/.moc/' storing the 
# mixersetting set when the server is shut-down.
# Note that there is a 'hidden' 'Amplification'
# setting in that file.
# Amplification (0-200) is used to scale
# the mixer setting (0-100). This results
# in a higher signal amplitude but may also
# produce clipping.
Softmixer_SaveState = yes

# Save equalizer state?
# If enabled, a file 'equalizer' will
# be created in '~/.moc/' storing the
# equalizer settings when the server is shut-down.
# There is a 'hidden' 'Mixin' setting in that file.
# Mixin (0.0-1.0) is used to determine how much of
# the original signal is used after equalizing.
# 0 means to only use the equalized sound, 1
# effectively disabled the mixer.
# Default is 0.25
Equalizer_SaveState = yes

# Show files with dot at the beginning?
ShowHiddenFiles        = no

# Start in the music directory if no arguments are given. If set to no, start
# in the current directory.
StartInMusicDir        = no

# Hide file name extensions.
HideFileExtension    = yes

# Show file format in menu.
ShowFormat        = yes

# Show file time in menu. Possible options: yes, no, IfAvailable - show the
# time only when it was read before (often works faster).
ShowTime        = IfAvailable

# Theme file. This can be absolute path or relative to
# /usr/share/moc/themes/ (depends on installation prefix) or ~/.moc/themes/
Theme            = transparent-background

# The theme used when running on an xterm.
# XTermTheme        = transparent-background

# MOC directory - where pid file, socket, and state files are stored.
# You can use ~ at the beginning.
MOCDir        = ~/.moc

# Use mmap() to read files. mmap() is much slower on NFS.
UseMmap            = no

# Assume this encoding for ID3 version 1/1.1 tags (mp3 files). Unlike ID3v2
# UTF-8 is not used here and MOC can't guess how tags are encoded. Another
# solution is using librcc (see the next option). This option is ignored
# if UseRCC is set to yes.
#ID3v1TagsEncoding        = WINDOWS-1250

# Use librcc to fix ID3 version 1/1.1 tags encoding.
#UseRCC                = yes

# Use librcc to filenames and directory names encoding.
#UseRCCForFilesystem            = yes

# Remember the playlist after exit?
SavePlaylist        = yes

# When using more than one client (interface) at a time, do they share the
# playlist?
SyncPlaylist        = yes

# Choose a keymap file (relative to ~/.moc/ or absolute path).
# Example keymap with description is included (keymap.example).
#Keymap            = my_keymap

# Use ASCII characters instead of graphic for drawing lines. This helps on
# some terminals.
ASCIILines        = no

# FastDirs, these allow you to jump directly to a directory, the key bindings
# are in the keymap file.
#Fastdir1 = /mp3/rock
#Fastdir2 = /mp3/electronic
#Fastdir3 = /mp3/rap
#Fastdir4 = /mp3/etc
#Fastdir5 = 
#Fastdir6 = 
#Fastdir7 = 
#Fastdir8 = 
#Fastdir9 = 
#Fastdir10 =

# How fast to seek? Number of seconds per key stroke.
#SeekTime        = 1

# How fast to seek (when using silent seeking)? Number of seconds per key
# stroke.
#SilentSeekTime        = 5

# Resample method to use. There are a few methods of resampling sound supported
# by libresamplerate. The default is the fastest (linear). Better description
# is here: http://www.mega-nerd.com/libsamplerate/api_misc.html#Converters
#
# High quality (based on bandlimited interpolation), but slow methods:
#
# SincBestQuality - really slow (I know you probably have an xx GHz processor,
#            but it's not enough to not see this in the top output :)
#            The worst case Signal-to-Noise Ratio is 97dB.
# SincMediumQuality - much faster.
# SincFastest - the fastest bandlimited interpolation.
#
# Poor quality, but much faster methods:
#
# ZeroOrderHold - really poor quality, but it's really fast.
# Linear - a bit better and a bit slower.
#
ResampleMethod        = Linear

# Always use this sample rate when opening the audio device (and resample the
# sound if necessary). When set to 0 the device is opened with the file's rate.
#ForceSampleRate    = 48000

# By default even if the sound card reports that it can output 24bit samples
# MOC converts 24bit PCM to 16bit. This option set to yes allows MOC to use
# 24bit output (for example MP3 decoder uses this format). This is disabled
# in the default configuration because there were reports that it prevents
# MP3 files from playing on some soundcards.
#Allow24bitOutput    = no

# Use realtime priority for output buffer thread. This will prevent gaps while
# playing even with heavy load. The user which runs MOC must have permissions
# to set such a priority. This could be dangerous, because it is possible that
# a bug in MOC will freeze your computer.
#UseRealtimePriority    = no

# Size of the in-memory cache for file tags in KB.
TagsCacheSize        = 256

# Number items in the playlist.
#PlaylistNumbering    = yes

# Main window layouts can be configured. You can change the position and the
# size of the menus (directory and playlist). You have 3 layouts and switch
# between then using the 'l' key (standard mapping). By default only 2 layouts
# are configured.
#
# The format is as follows:
# Each menu is described in the format NAME:POSITION_X,POSITION_Y,WIDTH,HEIGHT
# NAME is directory or playlist.
# The other parameters define position and size of the menu. They can be
# absolute numbers (like 10) or a percent value of the screen size (like 45%).
# WIDTH and HEIGHT can have value of FILL which means fill the screen from
# the menu's position to the border.
# Separate menu descriptions using a space.
# Menus may overlap.
# You must describe at least one menu (default is to fill the whole window).
# There must be at least one layout (Layout1) defined. Others can be empty ("").
#
# Examples:
#
# Just one layout, the directory will occupy the whole screen, the playlist
# will have 1/4 of the screen size and be positioned at lower right corner.
# Layout1 = "playlist:50%,50%,50%,50%"
# Layout2 = ""
# Layout3 = ""
#
# The screen is split into two parts: playlist at the top and the directory
# menu at the bottom. Playlist will occupy 10 lines and the directory menu
# the rest.
# Layout1 = "playlist:0,0,100%,10 directory:0,10,100%,FILL"
#
# Default configuration:
# Layout1        = "directory:0,0,50%,100% playlist:50%,0,50%,100%"
# Layout2        = "directory:0,0,100%,100% playlist:0,0,100%,100%"
# Layout3        = ""

# When the song changes, should the menu be scrolled so that the currently
# played file is visible?
FollowPlayedFile    = yes

# What to do if the interface was started and something from the playlist is
# playing? If CanStartInPlaylist is set to "yes", the interface will switch to
# the playlist. When set to "no" it will start from the last directory.
CanStartInPlaylist    = yes

# Executing external commands (1 - 10) invoked with key commands (F1 - F10 by
# default).
# Some arguments are substituted before executing:
# %f - file path
# %i - title made from tags
# %S - start block mark (in seconds)
# %E - end block mark (in seconds)
#
# Data from tags:
# %t - title
# %a - album
# %r - artist
# %n - track
# %m - time of the file (in seconds)
#
# Parameters above apply to the currently selected file. If you change them to
# capital letters, they are taken from the file currently playing.
#
# Programs are run using execv(), not a shell, so you can't do things like
# redirecting the output to a file. The command string is split using blank
# characters as separators, the first element is the command to be executed
# and the rest are parameters, so if you use "echo Playing: %I" we run program
# echo (from $PATH) with 2 parameters: 'Playing:' string and the title. Even
# if the title contains spaces it's still one parameter and it's safe if it
# contains `rm -rf /`.
#
# Examples:
# ExecCommand1        = "cp %f /mnt/usb_drive"
# ExecCommand2        = "/home/joe/now_playing %I"

# Display the cursor in the line with the selected file. This can be useful with
# a braille display.
UseCursorSelection    = no

# Set the terminal title when running under xterm.
SetXtermTitle        = yes

# Set the terminal title when running under screen.
SetScreenTitle        = yes

# Display full paths instead of just file names in the playlist.
#PlaylistFullPaths    = yes

# The following setting describes to how block markers are displayed
# in the play time progress bar.  Its value is a string of exactly three
# characters.  The first character is displayed in a position which
# corresponds to the time marked as the start of a block and the last
# character to the time marked as the end of the block.  The middle
# character is displayed instead if both the start and the end of the block
# would fall in the same position (within the resolution of the interface).
# You can turn off the displaying of these block marker positions by using
# three space characters.
#BlockDecorators    = "`\"'"

# How long (in seconds) to leave a message displayed on the screen.
# Setting this to a high value allows you to scroll through the messages
# using the 'hide_message' key.  Setting it to zero means you'll have to
# be quick to see any message at all.  Any new messages will queued up
# and displayed after the current message's linger time expires.
#MessageLingerTime    = 3

# Does MOC display a prefix on delayed messages indicating
# the number of queued messages still to be displayed?
#PrefixQueuedMessages    = yes

# String to append to the queued message count if any
# error messages are still waiting to be displayed.
#ErrorMessagesQueued    = "!"

# Enable oversampling (yes/no).
#ModPlug_Oversampling = yes
# Enable noise reduction (yes/no).
#ModPlug_NoiseReduction = yes
# Enable reverb (yes/no).
#ModPlug_Reverb = no
# Enable mega-bass (yes/no).
#ModPlug_MegaBass = no
# Enable surround (yes/no).
#ModPlug_Surround = no
# Resampling mode. One of FIR/SPLINE/LINEAR/NEAREST:
# FIR :      8 tap fir filter (extremely high quality).
# SPLINE :   Cubic spline interpolation (high quality).
# LINEAR :   Linear interpolation (fast, good quality).
# NEAREST :  No interpolation (very fast, extremely bad sound quality).
#ModPlug_ResamplingMode = FIR
# Number of channles (1 or 2).
#ModPlug_Channels = 2
# Bits per sample (8,16,32). 32 Bits seems to be buggy...
#ModPlug_Bits = 16 
# Sampling rate (11025, 22050, 44100, 48000).
#ModPlug_Frequency = 44100
# Reverb level 0(quiet)-100(loud).
#ModPlug_ReverbDepth = 0
# Reverb delay in ms, usually 40-200ms.
#ModPlug_ReverbDelay = 0
# Bass level 0(quiet)-100(loud).
#ModPlug_BassAmount = 0
# Bass cutoff in Hz (10-100).
#ModPlug_BassRange = 10
# Surround level 0(quiet)-100(heavy).
#ModPlug_SurroundDepth = 0
# Surround delay in ms, usually 5-40ms.
#ModPlug_SurroundDelay = 0
# Number of times to loop. Zero prevents looping. -1 loops forever.
#ModPlug_LoopCount = 0

#TiMidity-Options.
# Rate must be in between 8000 and 48000.
#TiMidity_Rate = 44100
# Bitrate is 8 or 16.
#TiMidity_Bits = 16
# Channels is 1 or 2.
#TiMidity_Channels = 2
# Volume-Range is 0-800.
#TiMidity_Volume = 100
# You can setup a TiMidity-Config-File here.
# Leave unset to use library defaults (/etc/timidity.cfg mostly).
#TiMidity_Config =


# SidPlay2-Options.
# Default length of a song if not in database (seconds).
#SidPlay2_DefaultSongLength = 180
# Play at least a specific time if song is shorter (seconds).
#SidPlay2_MinimumSongLength = 0
# Set path to a HVSC-compatible database (if not set, database is disabled).
#SidPlay2_Database
# Sampling Frequency (4000-48000Hz).
#SidPlay2_Frequency = 44100
# Sampling Resolution (8/16).
#SidPlay2_Bits = 16
# Playback Mode:
# "M": Mono (best for many SIDs).
# "S": Stereo.
# "L"/"R": Left / Right.
#SidPlay2_PlayMode = "M"
# Optimisation-level (0-2), 0 is best quality.
#SidPlay2_Optimisation = 0
# Use start-song information from SID (1) or start at first song (0).
# Songs before the start-song won't be played.
#SidPlay2_StartAtStart = 1
# Play sub-tunes.
#SidPlay2_PlaySubTunes = 1

# OnSongChange.
# Specify the full path (i.e. no ~) of an executable to run.
# Arguments will be passed, and you can use the following escapes:
#  %a artist
#  %r album
#  %f filename
#  %t title
#  %n track
#  %d file duration in XX:YY form
#  %D file duration, number of seconds
#
# No pipes/redirects can be used directly, but writing a shell
# script can do the job.
#
# Example:
#
#OnSongChange = "/home/jack/.moc/myscript %a %r"

# OnStop.
# Run the following command (full path, no arguments) when MOC changes state
# to stopped (when user stopped playing or changes a song).
#
#OnStop = "/home/jack/.moc/myscript_on_stop"

# This options determines what song to play after finishing all the songs in
# queue. Setting this to 'yes' causes MOC to play the song which follows the
# song played before playing the queue. If set to 'no', MOC will play the song
# after the last song in the queue if it was in the playlist. The default is
# 'yes' because this is the way other players usually behave. (Note that this
# option previously took the values 1 and 0; these are now deprecated in
# favour of 'yes' and 'no'.)
#QueueNextSongReturn = yes

* En fonctionnement dans U-RXVT :
(donc en se servant du fichier ".Xdefaults" pour les couleurs : http://crunchbanglinux-fr.org/forum/vie … hp?id=514)

LQO6O.png


* Script pour afficher ce que joue mocp à la demande (= Notification) :

#!/bin/bash
   INFO="`mocp --info | egrep "^Artist\:|^SongTitle\:|^Album\:" | sed -n 'p'`" 
  notify-send -t 4000 -i /home/kooka/.icons/mocp.png "       moc-player :" "$INFO"

* Raccourcis Openbox :

    <keybind key="W-Up">
      <action name="Execute">
        <execute>amixer set Master 3dB+</execute>
      </action>
    </keybind>
    <keybind key="W-Down">
      <action name="Execute">
        <execute>amixer set Master 3dB-</execute>
      </action>
    </keybind>
    <keybind key="C-m">
      <action name="Execute">
        <execute>sh /home/Stockage/Projets/Bash/moc-osd.sh</execute>
      </action>
    </keybind>
    <keybind key="W-space">
      <action name="Execute">
        <execute>mocp --toggle-pause</execute>
      </action>
    </keybind>
    <keybind key="W-Right">
      <action name="Execute">
        <execute>mocp --next</execute>
      </action>
    </keybind>
    <keybind key="W-Left">
      <action name="Execute">
        <execute>mocp --previous</execute>
      </action>
    </keybind>

    <keybind key="W-m">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>MocP</name>
        </startupnotify>
        <command>urxvt -e "mocp"</command>
      </action>
    </keybind>

N'hésitez pas à rajouter vos astuces, vos scripts, vos pipes-menus, bref tout ce qui peux améliorer le confort d'utilisation de cette belle application ! smile


Portable17p : CrunchBangLinux // EeePC : ArchLinux
Eeepad Transformer : Android Honeycomb 3.2 // GalaxyS : Android 2.2

Ma page DevArt : http://kookadimi.deviantart.com
Mes photos : http://www.fluidr.com/photos/kookadimi/sets

Hors ligne

#2 2011-02-11 11:09:19

peper
:(){ :| : & };:
Inscription : 2010-12-29
Messages : 144

Re : MoC : tout pour bien le contrôler !

J'arrive pas à faire tourner ton script. Il faut un paquet précis pour notify-send ?
Ton pipe-menu est bien, j'adopte smile

Juste une petite remarque pour tes codes: pense à mettre exit 0 à la fin de ton code. même si ça ne change rien à l'exécution c'est mieux.


Voila mes config:

j'affiche les notifications avec : moc_notify

#!/usr/bin/env python
# mocp_notify
# ----------
# A silly little python script for testing changes to notify-osd settings.

import pygtk
pygtk.require('2.0')
import pynotify
import sys
import gtk
import os
import string
if __name__ == '__main__':
    if not pynotify.init("mocp_notify"):
        sys.exit(1)
    if len(sys.argv)==1:
        os.popen("pkill notify-osd")
        title = os.popen("echo MOC : $(mocp -Q %state)","r").readline()
        p = os.popen("mocp -Q %file | rev | cut -d/ -f1 | rev","r")
        message = ""
        while 1:
            line = p.readline()
            if not line: break
            message = message + line
        image = "/usr/share/pixmaps/xfce4-mixer.xpm"
        n = pynotify.Notification(title, message, image)
        n.set_urgency(pynotify.URGENCY_LOW)
        n.set_timeout(10000)
        if not n.show():
            print "Failed to send notification"
            sys.exit(1)
        sys.exit()

Le code est complétement pompé de cb-fortune

J'appelle moc avec ce script qui démarre moc s'il n'a pas encore été lancé et charge une le fichier musique si la playlist est vide. Si je mais un argument il execute moc + l'argument.
moc_play

#! /bin/bash
# mocp_play

if ! test -z $1
    then
    mocp -$1
    
    else

    if mocp -Q %state
        then
        if test $(mocp -Q %state) = $(echo "STOP")
            then
            mocp -p
            else $(mocp -G)
            fi
        else
        mocp -S
        mocp -p
        state=$(mocp -Q %state)
        echo $state
        if test $(echo $state) = $(echo "STOP")
            then
            echo "add"
            mocp -a ~/data/music/
            mocp -p
            fi
        
        fi
            
    fi
            
if ! mocp_notify &
    then
    exit 1
    fi
    
exit 0

Dernier script pour fermé la fenêtre de moc déjà ouverte avant d'en réouvrir une (pour éviter d'avoir des fenêtres partout): moc_client

#! /bin/bash
# mocp_client

if ps x | grep mocp | grep Ss+ | grep -v grep #verifie si moc
    then
    kill -9 $(ps x | grep mocp | grep Ss+ | grep -v grep | cut -b-5)
    fi
if ! terminator -e 'mocp -T /usr/share/moc/themes/green_theme'
    then
    exit 1
    fi
    
exit 0

Tout mes scripts sont enregistrés dans "~/bin/" donc je n'ai pas ai mettre l'adresse en entier pour les appeler (car "bin/" est dans le $PATH).

Mes raccourcis sont:

<!-- moc -->
    <keybind key="W-m">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>Moc</name>
        </startupnotify>
        <command>mocp_client</command>
      </action>
    </keybind>
    <keybind key="W-Up">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>Moc_stop</name>
        </startupnotify>
        <command>mocp -s</command>
      </action>
    </keybind>
    <keybind key="W-Down">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>Moc_play</name>
        </startupnotify>
        <command>mocp_play</command>
      </action>
    </keybind>
    <keybind key="W-Left">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>Moc_previous</name>
        </startupnotify>
        <command>mocp_play r</command>
      </action>
    </keybind>
    <keybind key="W-Right">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>Moc_next</name>
        </startupnotify>
        <command>mocp_play f</command>
      </action>
    </keybind>
    <keybind key="W-S-Left">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>Moc_previous</name>
        </startupnotify>
        <command>mocp -k -1</command>
      </action>
    </keybind>
    <keybind key="W-S-Right">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>Moc_next</name>
        </startupnotify>
        <command>mocp -k +1</command>
      </action>
    </keybind>
    <keybind key="W-F11">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>Moc_down</name>
        </startupnotify>
        <command>mocp -v -5</command>
      </action>
    </keybind>
    <keybind key="W-F12">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>Moc_up</name>
        </startupnotify>
        <command>mocp -v +5</command>
      </action>
    </keybind>
    <keybind key="W-F10">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>Moc_quiet</name>
        </startupnotify>
        <command>mocp -v 0</command>
      </action>
    </keybind>
    <!-- /moc -->

Attention j'ai remplacé le raccourci W-m pour vlc par celui pour moc.
J'utilise la touche super car dans mon ancienne config la touche fn été pour Exaile. Et ça me permet de contrôler le volume du master et du PCM.

Voila c'est tout smile

Dernière modification par peper (2011-02-11 11:34:46)

Hors ligne

#3 2011-02-11 15:57:46

Kookaburra
#! /bin/modo
Inscription : 2010-09-26
Messages : 871
Site Web

Re : MoC : tout pour bien le contrôler !

peper a écrit :

J'arrive pas à faire tourner ton script. Il faut un paquet précis pour notify-send ?
Ton pipe-menu est bien, j'adopte smile

Il faut installer 'libnotify-bin'.
Merci pour le pipe. Pour être honnête, c'est une adaptation d'un script permettant de contrôler mpd, vu sur le forum ArchLinux wink


Moi aussi, je n'arrive pas à faire tourner ton script ! tongue
Il démarre, affiche une fois la chanson en cours, mais rien au changement de chansons hmm
Une idée ?


Portable17p : CrunchBangLinux // EeePC : ArchLinux
Eeepad Transformer : Android Honeycomb 3.2 // GalaxyS : Android 2.2

Ma page DevArt : http://kookadimi.deviantart.com
Mes photos : http://www.fluidr.com/photos/kookadimi/sets

Hors ligne

#4 2011-02-11 16:20:53

peper
:(){ :| : & };:
Inscription : 2010-12-29
Messages : 144

Re : MoC : tout pour bien le contrôler !

Pour les changements de piste tu lui passe comme paramètre "r" ou "f" et il change la piste et t'affiche la notification. Utilise les appels que j'ai mis dans mes raccourcis.

Hors ligne

#5 2011-02-11 16:32:47

Kookaburra
#! /bin/modo
Inscription : 2010-09-26
Messages : 871
Site Web

Re : MoC : tout pour bien le contrôler !

Soit, mais au changement automatique de piste (dans une playlist par ex, quand ça passe tout seul d'une chanson à l'autre ...), il ne se passe rien ?
C'est cette fonction que je recherche wink


Portable17p : CrunchBangLinux // EeePC : ArchLinux
Eeepad Transformer : Android Honeycomb 3.2 // GalaxyS : Android 2.2

Ma page DevArt : http://kookadimi.deviantart.com
Mes photos : http://www.fluidr.com/photos/kookadimi/sets

Hors ligne

#6 2011-02-11 17:01:32

Kookaburra
#! /bin/modo
Inscription : 2010-09-26
Messages : 871
Site Web

Re : MoC : tout pour bien le contrôler !

Nouvelle version du "Pipe-Menu", j'aimais pas l'aspect de l'autre en fait big_smile

M0zgx.png


# moc-ob-pipe - control moc in your openbox menu
# chmod +x mmoc-ob-pipe.sh, and place:
# "<menu id="pipe-moc-menu" label="MMusicOnConsole Pipe" execute="/path/to/script/moc-ob-pipe.sh" />"
# somewhere in your menu.

# set variables
#playing=`mocp --info | egrep "^Artist\:|^SongTitle\:|^Album\:" | sed -n 'p'`
ARTIST="`mocp -i | grep 'Artist:' | sed -e 's/^.*: //'`"
SONGTITLE="`mocp -i | grep 'SongTitle:' | sed -e 's/^.*: //'`"
ALBUM="`mocp -i | grep 'Album:' | sed -e 's/^.*: //'`"
playing1=`echo "Titre : $SONGTITLE"`
playing2=`echo "Album : $ALBUM"`
playing3=`echo "Artiste : $ARTIST"`
nowstatus=`mocp -Q %state`
 
# echo menu
 
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
echo "<openbox_pipe_menu>"
echo " <menu id=\"MoC-playing\" label=\"$nowstatus\">"
echo " <item label=\"$playing1\">"
echo " <action name=\"Execute\"><execute>mocp --toggle-pause</execute></action>"
echo " </item>"
echo " <item label=\"$playing2\">"
echo " <action name=\"Execute\"><execute>mocp --toggle-pause</execute></action>"
echo " </item>"
echo " <item label=\"$playing3\">"
echo " <action name=\"Execute\"><execute>mocp --toggle-pause</execute></action>"
echo " </item>"
echo " </menu>"
echo " <separator />"
echo " <item label=\"play\">"
echo " <action name=\"Execute\"><execute>mocp --play</execute></action>"
echo " </item>"
echo " <item label=\"pause\">"
echo " <action name=\"Execute\"><execute>mocp --toggle-pause</execute></action>"
echo " </item>"
echo " <item label=\"prev\">"
echo " <action name=\"Execute\"><execute>mocp --previous</execute></action>"
echo " </item>"
echo " <item label=\"next\">"
echo " <action name=\"Execute\"><execute>mocp --next</execute></action>"
echo " </item>"
echo " <item label=\"stop\">"
echo " <action name=\"Execute\"><execute>mocp --stop</execute></action>"
echo " </item>"
echo "</openbox_pipe_menu>"

Portable17p : CrunchBangLinux // EeePC : ArchLinux
Eeepad Transformer : Android Honeycomb 3.2 // GalaxyS : Android 2.2

Ma page DevArt : http://kookadimi.deviantart.com
Mes photos : http://www.fluidr.com/photos/kookadimi/sets

Hors ligne

#7 2011-02-11 17:51:13

peper
:(){ :| : & };:
Inscription : 2010-12-29
Messages : 144

Re : MoC : tout pour bien le contrôler !

Non il ne se passe rien. Pour ça il faudrait soit faire un démon qui surveille les changements de pistes (mais ça va encore bouffer du CPU) soit modifier moc pour qu'il affiche lui même les notifications (il y a du boulot mais ça peut être fun).

Dernière modification par peper (2011-02-11 17:51:39)

Hors ligne

#8 2011-02-11 18:02:44

zubi33
Crunchbanger
Inscription : 2010-10-12
Messages : 138

Re : MoC : tout pour bien le contrôler !

Fort intéressant tous ces scripts, mais de nos jours, n'est-ce pas de la Geekattitude nostalgique cool


---------------------------------------------
|    CRUNCHBANG #! 11 Waldorf + Openbox    |
|                    ASUS Zenbook UX31E           |
--------------------------------------------

Hors ligne

#9 2011-02-11 18:07:42

peper
:(){ :| : & };:
Inscription : 2010-12-29
Messages : 144

Re : MoC : tout pour bien le contrôler !

Euh... surement oui. C'est de l'artisanat geek smile

Hors ligne

#10 2011-02-11 18:14:05

Kookaburra
#! /bin/modo
Inscription : 2010-09-26
Messages : 871
Site Web

Re : MoC : tout pour bien le contrôler !

peper a écrit :

Non il ne se passe rien. Pour ça il faudrait soit faire un démon qui surveille les changements de pistes (mais ça va encore bouffer du CPU)

On verra bien si ça me bouffe du CPU big_smile

#!/bin/bash
while true
do
    STATUT=`mocp -Q %state`
    if [ "$STATUT" = "PAUSE" ]; then 
            sleep 1
    fi
    if [ "$STATUT" = "STOP" ]; then 
            sleep 1
    fi
    if [ "$STATUT" = "PLAY" ]; then
            INFO1="`mocp --info | egrep "^Artist\:|^SongTitle\:|^Album\:" | sed -n 'p'`" 
            sleep 1
            INFO2="`mocp --info | egrep "^Artist\:|^SongTitle\:|^Album\:" | sed -n 'p'`" 
            if [ "$INFO1" = "$INFO2" ]; then
            echo ""
            else
                INFO="`mocp --info | egrep "^Artist\:|^SongTitle\:|^Album\:" | sed -n 'p'`"
                notify-send -t 3000 -i /home/kooka/.icons/mocp.png "       moc-player :" "$INFO"
            fi
    fi
done

Testé chez moi, ça fonctionne ! Comment je regarde ce que ça me bouffe en ressources d'ailleurs ? Je vais regarder si je le vois dans "htop", on verra bien ! tongue

Celui-là, je l'ai fait tout seul comme un grand, sans rien pomper ! si si promis lol N'empèches, c'est sympa d'arriver à faire un truc pareil tout seul (j'ai pas joui, mais presque cool yikes )


Portable17p : CrunchBangLinux // EeePC : ArchLinux
Eeepad Transformer : Android Honeycomb 3.2 // GalaxyS : Android 2.2

Ma page DevArt : http://kookadimi.deviantart.com
Mes photos : http://www.fluidr.com/photos/kookadimi/sets

Hors ligne

#11 2011-02-11 20:07:27

peper
:(){ :| : & };:
Inscription : 2010-12-29
Messages : 144

Re : MoC : tout pour bien le contrôler !

Ce qui est important dans une boucle infinie comme ça, c'est sa fréquence. Là ta notification apparaît au pire une seconde après le changement de piste. Et tu exécute la boucle une fois par seconde. Si tu avais voulu une plus grande précision tu aurais fais executer là boucle plus souvent: donc plus de calculs et plus de ressources consommées.
Chez moi ça doit consommer grand max 2% de CPU (j'ai la charge des processeurs affichée par conky).

Ton script est bon mais je me suis permis quelques modifications :

D'abord tu test puis tu attend et tu reteste. Et en fonction de ça tu affiche ou pas une notification. Mais finalement il faut que le changement est lieu lors de l'execution du sleep 1 ligne 13 sinon tu ne la voie pas et pas de notification.
Il faut donc réutiliser la variable INFO de l'itération précédente. c'est pour ça que j'initialise INFO1 au début qui correspond ensuite à "la valeur précédente".
Cette technique te permet aussi de réduire le nombre d'appel à moc.
Comme le comportement du programme est le même si moc est en pause ou sur stop, on peut faire un test avec un OU.
Enfin je préfère tester les noms des fichiers où je suis sur qu'il n'y a pas de doublon (chez moi les champs artiste ou albums ne sont pas toujours renseignés).
Et à la fin du code un petit exit 0 pour rester fidèle à la convention UNIX.

edit: Lorsque le serveur de moc n'est pas démarré, la boucle passe à l'itération suivante sans attendre (sans faire de sleep). Et dans ce cas tu a un processeur qui se met à tourner à fond. Le plus simple est de tester si le lecteur est sur play: si c'est le cas on teste le changement de piste, sinon (pause, stop, ou serveur non lancé) on attend.

#!/bin/bash

INFO1=`mocp -Q %file`

while true
do
    STATUT=`mocp -Q %state`
    if [ "$STATUT" = "PLAY" ]; then
        INFO2=$INFO1
        INFO1=`mocp -Q %file`
        if [ "$INFO1" = "$INFO2" ]; then
            sleep 1
        else
            INFO="`mocp --info | egrep "^Artist\:|^SongTitle\:|^Album\:" | sed -n 'p'`"
            notify-send -t 3000 -i /home/peper/.icons/mocp.png "       moc-player :" "$INFO"
        fi
    else
        sleep 1
    fi
done

exit 0

Bon maintenant je suis sûr que tu me déteste big_smile

Dernière modification par peper (2011-02-14 11:21:04)

Hors ligne

#12 2011-02-26 16:07:17

Kookaburra
#! /bin/modo
Inscription : 2010-09-26
Messages : 871
Site Web

Re : MoC : tout pour bien le contrôler !

Juste pour le plaisir tongue
Script venant du forum ArchLinux US, qui permet d'utiliser "dmenu" pour utiliser Moc (même en version "serveur").
On peut soit l'associer à un raccourci clavier (Alt+F5 chez moi), soit à une entrée dans le menu Openbox, ...

* En images (ça se passe en haut de l'écran) :

BnoN8.png


* Le script :

#!/bin/sh

ACTION=`printf "playlist\npause/play\nnext\nprevious\nstart\nexit\nopen\nload\nshuffle\nrepeat\n" | dmenu -i $*`

if [ "$ACTION" == 'playlist' ]; then
  mocp -p
fi

if [ "$ACTION" == 'pause/play' ]; then
  mocp -G
fi

if [ "$ACTION" == 'next' ]; then
 mocp -f  
fi

if [ "$ACTION" == 'previous' ]; then
  mocp -r
fi

if [ "$ACTION" == 'start' ]; then
 mocp -S
 dmenu_mocp
fi

if [ "$ACTION" == 'exit' ]; then
 mocp -x
fi

if [ "$ACTION" == 'open' ]; then 
 urxvt -e mocp
fi

if [ "$ACTION" == 'load' ]; then
    mocp -c &&
  play=$(find ~/ -name *.m3u | dmenu -i $*)
  echo $play
  mocp -a "$play"
    mocp -p
fi
if [ "$ACTION" == 'shuffle' ]; then
 mocp -t shuffle
fi

if [ "$ACTION" == 'repeat' ]; then
  mocp -t repeat    
fi

NB : on peut appliquer ce principe à toutes les applications, le script est très simple à modifier pour une autre application wink


Portable17p : CrunchBangLinux // EeePC : ArchLinux
Eeepad Transformer : Android Honeycomb 3.2 // GalaxyS : Android 2.2

Ma page DevArt : http://kookadimi.deviantart.com
Mes photos : http://www.fluidr.com/photos/kookadimi/sets

Hors ligne

Pied de page des forums