edje - feature - add channel types for sounds and ability to mute them
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>
Sun, 9 Feb 2014 10:08:12 +0000 (19:08 +0900)
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>
Sun, 9 Feb 2014 10:08:12 +0000 (19:08 +0900)
this adds a new feature to be able to assign a sample to a given
"type" of audio channel, and then to be able to mute these from code.

data/edje/include/edje.inc
src/bin/edje/edje_cc_handlers.c
src/lib/edje/Edje_Common.h
src/lib/edje/edje_data.c
src/lib/edje/edje_embryo.c
src/lib/edje/edje_multisense.c
src/lib/edje/edje_private.h
src/lib/edje/edje_program.c

index 1cf7b89..828380b 100644 (file)
@@ -235,8 +235,8 @@ native set_state_val(part_id, State_Param:p, ...);
 native get_state_val(part_id, State_Param:p, ...);
 
 /* Multisense */
-native       play_sample      (sample_name[], Float:speed);
-native       play_tone        (tone_name[], Float:duration);
+native       play_sample      (sample_name[], Float:speed, ...);
+native       play_tone        (tone_name[], Float:duration, ...);
 
 /***********************************************************/
 /* Edje physics calls.                                     */
index 0ea056d..dda4116 100644 (file)
@@ -9126,7 +9126,7 @@ st_collections_group_programs_program_in(void)
            action: FOCUS_OBJECT;\n
            action: PARAM_COPY "src_part" "src_param" "dst_part" "dst_param";\n
            action: PARAM_SET "part" "param" "value";\n
-           action: PLAY_SAMPLE "sample name" speed (speed of sample - 1.0 is original speed - faster is higher pitch);\n
+           action: PLAY_SAMPLE "sample name" speed (speed of sample - 1.0 is original speed - faster is higher pitch) [channel optional EFFECT/FX | BACKGROUND/BG | MUSIC/MUS | FOREGROUND/FG | INTERFACE/UI | INPUT | ALERT;\n
            action: PLAY_TONE "tone name" duration in seconds ( Range 0.1 to 10.0 );\n
            action: PHYSICS_IMPULSE 10 -23.4 0;\n
            action: PHYSICS_TORQUE_IMPULSE 0 2.1 0.95;\n
@@ -9199,6 +9199,16 @@ st_collections_group_programs_program_action(void)
                }
           }
         ep->speed = parse_float_range(2, 0.0, 100.0);
+        if (get_arg_count() >= 4)
+          ep->channel = parse_enum(3,
+                                   "EFFECT", 0, "FX", 0,
+                                   "BACKGROUND", 1, "BG", 1,
+                                   "MUSIC", 2, "MUS", 2,
+                                   "FOREGROUND", 3, "FG", 3,
+                                   "INTERFACE", 4, "UI", 4,
+                                   "INPUT", 5,
+                                   "ALERT", 6,
+                                   NULL);
      }
    else if (ep->action == EDJE_ACTION_TYPE_SOUND_TONE)
      {
@@ -9303,6 +9313,8 @@ st_collections_group_programs_program_action(void)
       case EDJE_ACTION_TYPE_PHYSICS_ROT_SET:
         check_arg_count(5);
         break;
+      case EDJE_ACTION_TYPE_SOUND_SAMPLE:
+        break;
       default:
        check_arg_count(3);
      }
index a2dbf13..9d83fb5 100644 (file)
@@ -2026,3 +2026,74 @@ EAPI const Edje_Perspective *edje_evas_global_perspective_get(const Evas *e);
 /**
  * @}
  */
+
+/**
+ * @defgroup Edje_Audio Edje Audio
+ *
+ * @brief Functions to manipulate audio abilities in edje.
+ *
+ * Perspective is a graphical tool that makes objets represented in 2D
+ * look like they have a 3D appearance.
+ *
+ * Edje allows us to use perspective on any edje object. This group of
+ * functions deal with the use of perspective, by creating and configuring
+ * a perspective object that must set to a edje object or a canvas,
+ * affecting all the objects inside that have no particular perspective
+ * set already.
+ *
+ * @ingroup Edje_Audio
+ *
+ * @{
+ */
+
+/**
+ * Identifiers of Edje message types, which can be sent back and forth
+ * code and a given Edje object's theme file/group.
+ *
+ * @see edje_audio_channel_mute_set()
+ * @see edje_audio_channel_mute_get()
+ * 
+ * @since 1.9
+ */
+typedef enum _Edje_Channel
+{
+   EDJE_CHANNEL_EFFECT = 0, /**< Standard audio effects */
+   EDJE_CHANNEL_BACKGROUND = 1, /**< Background audio sounds  */
+   EDJE_CHANNEL_MUSIC = 2, /**< Music audio */
+   EDJE_CHANNEL_FOREGROUND = 3, /**< Foreground audio sounds */
+   EDJE_CHANNEL_INTERFACE = 4, /**< Sounds related to the interface */
+   EDJE_CHANNEL_INPUT = 5, /**< Sounds related to regular input */
+   EDJE_CHANNEL_ALERT = 6, /**< Sounds for major alerts */
+   EDJE_CHANNEL_ALL = 7 /**< All audio channels (convenience) */
+} Edje_Channel;
+
+/**
+ * Set the mute state of audio for the process as a whole
+ * 
+ * @param channel The channel to set the mute state of
+ * @param mute The mute state
+ * 
+ * This sets the mute (no output) state of audio for the given channel.
+ * 
+ * @see edje_audio_channel_mute_get()
+ * 
+ * @since 1.9
+ */
+EAPI void edje_audio_channel_mute_set(Edje_Channel channel, Eina_Bool mute);
+
+/**
+ * Get the mute state of the given channel
+ * 
+ * @param channel The channel to get the mute state of
+ * @return The mute state of the channel
+ * 
+ * @see edje_audio_channel_mute_set()
+ *
+ * @since 1.9
+ */
+EAPI Eina_Bool edje_audio_channel_mute_get(Edje_Channel channel);
+
+/**
+ * @}
+ */
+
index 3a11cff..fc76593 100644 (file)
@@ -477,6 +477,7 @@ _edje_edd_init(void)
    EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "physics.y", physics.y, EET_T_DOUBLE);
    EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "physics.z", physics.z, EET_T_DOUBLE);
 #endif
+   EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "channel", channel, EET_T_UCHAR);
 
    EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Edje_Part_Image_Id);
    _edje_edd_edje_part_image_id =
index cb20648..d09ae72 100644 (file)
@@ -73,8 +73,8 @@
  * set_state(part_id, state[], Float:state_val)
  * get_state(part_id, dst[], maxlen, &Float:val)
  * set_tween_state(part_id, Float:tween, state1[], Float:state1_val, state2[], Float:state2_val)
- * play_sample(sample_name, speed)
- * play_tone(tone_name, duration)
+ * play_sample(sample_name, speed, ...)
+ * play_tone(tone_name, duration, ...)
  * run_program(program_id)
  * Direction:get_drag_dir(part_id)
  * get_drag(part_id, &Float:dx, &Float:&dy)
@@ -915,13 +915,18 @@ _edje_embryo_fn_play_sample(Embryo_Program *ep, Embryo_Cell *params)
    Edje *ed;
    char *sample_name = NULL;
    float speed = 1.0;
+   int channel = 0;
 
-   CHKPARAM(2);
+   if (params[0] < (int) (sizeof(Embryo_Cell) * 2))
+     return 0;
    ed = embryo_program_data_get(ep);
    GETSTR(sample_name, params[1]);
    if ((!sample_name)) return 0;
    speed = EMBRYO_CELL_TO_FLOAT(params[2]);
-   _edje_multisense_internal_sound_sample_play(ed, sample_name, (double)speed);
+   if (params[0] == (int) (sizeof(Embryo_Cell) * 3))
+     GETINT(channel, params[3]);
+   _edje_multisense_internal_sound_sample_play(ed, sample_name,
+                                               (double)speed, channel);
    return 0;
 }
 
@@ -931,13 +936,18 @@ _edje_embryo_fn_play_tone(Embryo_Program *ep, Embryo_Cell *params)
    Edje *ed;
    char *tone_name = NULL;
    float duration = 0.1;
+   int channel = 0;
 
-   CHKPARAM(2);
+   if (params[0] < (int) (sizeof(Embryo_Cell) * 2))
+     return 0;
    ed = embryo_program_data_get(ep);
    GETSTR(tone_name, params[1]);
    if ((!tone_name)) return 0;
    duration = EMBRYO_CELL_TO_FLOAT(params[2]);
-   _edje_multisense_internal_sound_tone_play(ed, tone_name, (double) duration);
+   if (params[0] == (int) (sizeof(Embryo_Cell) * 3))
+     GETINT(channel, params[3]);
+   _edje_multisense_internal_sound_tone_play(ed, tone_name,
+                                             (double)duration, channel);
    return 0;
 }
 
index daa878e..a8ae628 100644 (file)
@@ -80,7 +80,8 @@ eet_snd_file_tell(void *data, Eo *eo_obj EINA_UNUSED)
    return vf->offset;
 }
 
-static void _free(void *data)
+static void
+_free(void *data)
 {
    struct _edje_multisense_eet_data *eet_data = data;
 
@@ -90,18 +91,58 @@ static void _free(void *data)
    free(data);
    outs--;
 }
+
+static Eina_Bool _channel_mute_states[8] = { 0 };
+
+static Eina_Bool
+_channel_mute(Edje *ed EINA_UNUSED, int channel)
+{
+   // ed lets use set mute per object... but for now no api's for this
+   // if all are muted ... then all!
+   if (_channel_mute_states[7]) return EINA_TRUE;
+   if ((channel < 0) || (channel > 7)) return EINA_FALSE;
+   return _channel_mute_states[channel];
+   return EINA_FALSE;
+}
+
+#endif
+
+EAPI void
+edje_audio_channel_mute_set(Edje_Channel channel, Eina_Bool mute)
+{
+#ifdef ENABLE_MULTISENSE
+   if ((channel < 0) || (channel > 7)) return;
+   _channel_mute_states[channel] = mute;
+#else
+   (void) channel;
+   (void) mute;
 #endif
+}
+
+EAPI Eina_Bool
+edje_audio_channel_mute_get(Edje_Channel channel)
+{
+#ifdef ENABLE_MULTISENSE
+   if ((channel < 0) || (channel > 7)) return EINA_FALSE;
+   return _channel_mute_states[channel];
+#else
+   (void) channel;
+   return EINA_FALSE;
+#endif
+}
 
 Eina_Bool
-_edje_multisense_internal_sound_sample_play(Edje *ed, const char *sample_name, const double speed)
+_edje_multisense_internal_sound_sample_play(Edje *ed, const char *sample_name, const double speed, int channel)
 {
- #ifdef ENABLE_MULTISENSE
+#ifdef ENABLE_MULTISENSE
    Eo *in;
    Edje_Sound_Sample *sample;
    char snd_id_str[255];
    int i;
    Eina_Bool ret;
 
+   if (_channel_mute(ed, channel)) return EINA_FALSE;
+   
    if (outfail) return EINA_FALSE;
    
    if (!sample_name)
@@ -189,12 +230,13 @@ _edje_multisense_internal_sound_sample_play(Edje *ed, const char *sample_name, c
    (void) ed;
    (void) sample_name;
    (void) speed;
+   (void) channel;
    return EINA_FALSE;
 #endif
 }
 
 Eina_Bool
-_edje_multisense_internal_sound_tone_play(Edje *ed, const char *tone_name, const double duration)
+_edje_multisense_internal_sound_tone_play(Edje *ed, const char *tone_name, const double duration, int channel)
 {
 #ifdef ENABLE_MULTISENSE
    unsigned int i;
@@ -208,6 +250,8 @@ _edje_multisense_internal_sound_tone_play(Edje *ed, const char *tone_name, const
         return EINA_FALSE;
      }
    
+   if (_channel_mute(ed, channel)) return EINA_FALSE;
+
    if (outfail) return EINA_FALSE;
    
    if ((!ed) || (!ed->file) || (!ed->file->sound_dir))
@@ -245,6 +289,7 @@ _edje_multisense_internal_sound_tone_play(Edje *ed, const char *tone_name, const
    (void) ed;
    (void) duration;
    (void) tone_name;
+   (void) channel;
    return EINA_FALSE;
 #endif
 
index a057d8e..698d085 100644 (file)
@@ -676,7 +676,7 @@ struct _Edje_Program /* a conditional program to be run */
       double z;
    } physics;
 #endif
-
+   unsigned char channel;
    Eina_Bool exec : 1;
 };
 
@@ -2427,8 +2427,8 @@ void _edje_subobj_unregister(Edje *ed, Evas_Object *ob);
 
 void _edje_multisense_init(void);
 void _edje_multisense_shutdown(void);
-Eina_Bool _edje_multisense_internal_sound_sample_play(Edje *ed, const char *sample_name, const double speed);
-Eina_Bool _edje_multisense_internal_sound_tone_play(Edje *ed, const char *tone_name, const double duration);
+Eina_Bool _edje_multisense_internal_sound_sample_play(Edje *ed, const char *sample_name, const double speed, int channel);
+Eina_Bool _edje_multisense_internal_sound_tone_play(Edje *ed, const char *tone_name, const double duration, int channel);
 
 void _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *state);
 
index a3b1747..ac32aa5 100644 (file)
@@ -877,12 +877,12 @@ low_mem_current:
       case EDJE_ACTION_TYPE_SOUND_SAMPLE:
          if (_edje_block_break(ed))
            goto break_prog;
-         _edje_multisense_internal_sound_sample_play(ed, pr->sample_name, pr->speed);
+         _edje_multisense_internal_sound_sample_play(ed, pr->sample_name, pr->speed, pr->channel);
          break;
       case EDJE_ACTION_TYPE_SOUND_TONE:
          if (_edje_block_break(ed))
            goto break_prog;
-         _edje_multisense_internal_sound_tone_play(ed, pr->tone_name, pr->duration);
+         _edje_multisense_internal_sound_tone_play(ed, pr->tone_name, pr->duration, pr->channel);
          break;
       case EDJE_ACTION_TYPE_PARAM_COPY:
            {