Author: duncan
Date: Thu Jun  7 16:16:36 2007
New Revision: 9663

Added:
   branches/rel-1/freevo/src/audio/sounds.py   (contents, props changed)
Modified:
   branches/rel-1/freevo/ChangeLog
   branches/rel-1/freevo/freevo_config.py
   branches/rel-1/freevo/src/menu.py

Log:
[ 1732380 ] OSD actions sounds
Patch from Adam Charrett applied


Modified: branches/rel-1/freevo/ChangeLog
==============================================================================
--- branches/rel-1/freevo/ChangeLog     (original)
+++ branches/rel-1/freevo/ChangeLog     Thu Jun  7 16:16:36 2007
@@ -17,6 +17,7 @@
 --------------------------------
 
  * Added personal web pages to the webserver, using PERSONAL_WWW_PAGE 
(F#1729595)
+ * Added sounds to menu selection, enabled with OSD_SOUNDS_ENABLED (F#1732380)
  * Updated childapp to use subprocess instead of popen (F#1729597)
  * Updated local_conf.py.example with MPLAYER_HAS_FIELD_DOMINANCE (F#1729404)
  * Updated system sensors for a configurable path (B#1731892)

Modified: branches/rel-1/freevo/freevo_config.py
==============================================================================
--- branches/rel-1/freevo/freevo_config.py      (original)
+++ branches/rel-1/freevo/freevo_config.py      Thu Jun  7 16:16:36 2007
@@ -280,6 +280,7 @@
         Added RECORDSERVER_LOGGING to allow different levels of errors to be 
reported
         Changed VIDEO_INTERLACING to VIDEO_DEINTERLACE to be more consistent 
with autovars
         Added SENSORS_PLATFORM_PATH and SENSORS_I2CDEV_PATH for sensor paths
+        Added OSD_SOUNDS_ENABLED defaulted to False for menu sounds
      ''' ),
 ]
 
@@ -1298,6 +1299,16 @@
 
 if CONF.display in ( 'dxr3', 'dga' ):
     OSD_UPDATE_COMPLETE_REDRAW = 1
+#
+# OSD sound effects
+#
+OSD_SOUNDS_ENABLED=False
+
+OSD_SOUNDS= {
+    'menu.navigate': None,
+    'menu.back_one': None,
+    'menu.select'  : None
+}
 
 # ======================================================================
 # Freevo remote control settings:

Added: branches/rel-1/freevo/src/audio/sounds.py
==============================================================================
--- (empty file)
+++ branches/rel-1/freevo/src/audio/sounds.py   Thu Jun  7 16:16:36 2007
@@ -0,0 +1,123 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------
+# sounds.py - Sound effects for the freevo gui
+# -----------------------------------------------------------------------
+# $Id$
+#
+# Notes:
+# Todo:
+#
+# -----------------------------------------------------------------------
+# $Log$
+#
+# -----------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002 Krister Lagerstrom, et al.
+# Please see the file freevo/Docs/CREDITS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# ----------------------------------------------------------------------- */
+
+import os.path
+import time
+
+import pygame.mixer
+
+import config
+
+
+
+# Used to cache Sound objects for configurable sounds
+sounds_cache = {}
+
+
+def load_sound(sound):
+    """
+    Return a pygame.mixer.Sound object based on sound.
+    sound can be an string - containing the name of a sound effect or a 
filename,
+    a pygame.mixer.Sound object or an file-like object.
+    If sound is the name of a sound effect the pygame.mixer.Sound object will 
be
+    cached for use again.
+    """
+    if not config.OSD_SOUNDS_ENABLED:
+        return None
+
+    sound_object = None
+
+    if isinstance(sound,str):
+        # sound refers to a configurable sound
+        if sound in config.OSD_SOUNDS:
+            # Check to see if we have already loaded this sound effect
+            if sound in sounds_cache:
+                sound_object = sounds_cache[sound]
+            else:
+                sound_file = config.OSD_SOUNDS[sound]
+                if sound_file:
+                    try:
+                        sound_object = pygame.mixer.Sound(sound_file)
+                    except:
+                        pass
+
+                    # Even if we fail to load the file cache the sound
+                    # anyway so its faster next time (as we won't bother to
+                    # try and load it)
+                    sounds_cache[sound] = sound_object
+
+        # sound refers to a file
+        elif os.path.exists(sound):
+            try:
+                sound_object = pygame.mixer.Sound(sound)
+            except:
+                pass
+
+    elif isinstance(sound, pygame.mixer.Sound):
+        sound_object = sound
+    else:
+        try:
+            sound_object = pygame.mixer.Sound(sound)
+        except:
+            pass
+
+    return sound_object
+
+
+def play_sound(sound):
+    """
+    Play a sound effect.
+    The sound will only be played if UI_SOUNDS_ENABLED is True.
+    sound can be an string - containing a sound effect name or a filename, a
+    pygame.mixer.Sound object or an file-like object.
+    """
+    if config.OSD_SOUNDS_ENABLED and sound is not None:
+        sound_object = load_sound(sound)
+
+        if sound_object:
+            sound_object.play()
+            time.sleep(0.2)
+
+
+if config.OSD_SOUNDS_ENABLED:
+    try:
+        # Initialise the mixer
+        pygame.mixer.init(44100,-16,2, 1024 * 3)
+    except:
+        print 'Mixer initialisation failed, OSD sounds disabled!'
+        config.OSD_SOUNDS_ENABLED = False
+
+# 'Known' sounds
+MENU_NAVIGATE = load_sound('menu.navigate') # Left/Right/Up/Down menu events
+MENU_BACK_ONE = load_sound('menu.back_one')
+MENU_SELECT   = load_sound('menu.select')

Modified: branches/rel-1/freevo/src/menu.py
==============================================================================
--- branches/rel-1/freevo/src/menu.py   (original)
+++ branches/rel-1/freevo/src/menu.py   Thu Jun  7 16:16:36 2007
@@ -37,6 +37,7 @@
 import skin
 import rc
 
+from audio import sounds
 from event import *
 from item import Item
 from gui import GUIObject, AlertBox
@@ -487,6 +488,7 @@
             return
 
         if event == MENU_BACK_ONE_MENU:
+            sounds.play_sound(sounds.MENU_BACK_ONE)
             self.back_one_menu()
             return
 
@@ -528,6 +530,7 @@
 
         if event == MENU_UP:
             curr_selected = self.all_items.index(menu.selected)
+            sounds.play_sound(sounds.MENU_NAVIGATE)
             if curr_selected-self.cols < 0 and \
                    menu.selected != menu.choices[0]:
                 self.goto_prev_page(arg='no_refresh')
@@ -548,6 +551,7 @@
 
         elif event == MENU_DOWN:
             curr_selected = self.all_items.index(menu.selected)
+            sounds.play_sound(sounds.MENU_NAVIGATE)
             if curr_selected+self.cols > len(self.all_items)-1 and \
                    menu.page_start + len(self.all_items) < len(menu.choices):
 
@@ -612,6 +616,7 @@
             if not len(self.menu_items):
                 return
 
+            sounds.play_sound(sounds.MENU_NAVIGATE)
             curr_selected = self.all_items.index(menu.selected)
             if curr_selected == 0:
                 self.goto_prev_page(arg='no_refresh')
@@ -632,6 +637,7 @@
             if not len(self.menu_items):
                 return
 
+            sounds.play_sound(sounds.MENU_NAVIGATE)
             curr_selected = self.all_items.index(menu.selected)
             if curr_selected == len(self.all_items)-1:
                 self.goto_next_page(arg='no_refresh')
@@ -655,6 +661,7 @@
             action = None
             arg    = None
 
+            sounds.play_sound(sounds.MENU_SELECT)
             try:
                 action = menu.selected.action
             except AttributeError:

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to