edje - feature - add channel types for sounds and ability to mute them

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.
This commit is contained in:
Carsten Haitzler 2014-02-09 19:08:12 +09:00
parent 7c7f2eb300
commit db1990020a
8 changed files with 158 additions and 19 deletions

View File

@ -235,8 +235,8 @@ native set_state_val(part_id, State_Param:p, ...);
native get_state_val(part_id, State_Param:p, ...); native get_state_val(part_id, State_Param:p, ...);
/* Multisense */ /* Multisense */
native play_sample (sample_name[], Float:speed); native play_sample (sample_name[], Float:speed, ...);
native play_tone (tone_name[], Float:duration); native play_tone (tone_name[], Float:duration, ...);
/***********************************************************/ /***********************************************************/
/* Edje physics calls. */ /* Edje physics calls. */

View File

@ -9126,7 +9126,7 @@ st_collections_group_programs_program_in(void)
action: FOCUS_OBJECT;\n action: FOCUS_OBJECT;\n
action: PARAM_COPY "src_part" "src_param" "dst_part" "dst_param";\n action: PARAM_COPY "src_part" "src_param" "dst_part" "dst_param";\n
action: PARAM_SET "part" "param" "value";\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: PLAY_TONE "tone name" duration in seconds ( Range 0.1 to 10.0 );\n
action: PHYSICS_IMPULSE 10 -23.4 0;\n action: PHYSICS_IMPULSE 10 -23.4 0;\n
action: PHYSICS_TORQUE_IMPULSE 0 2.1 0.95;\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); 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) 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: case EDJE_ACTION_TYPE_PHYSICS_ROT_SET:
check_arg_count(5); check_arg_count(5);
break; break;
case EDJE_ACTION_TYPE_SOUND_SAMPLE:
break;
default: default:
check_arg_count(3); check_arg_count(3);
} }

View 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);
/**
* @}
*/

View 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.y", physics.y, EET_T_DOUBLE);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "physics.z", physics.z, EET_T_DOUBLE); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "physics.z", physics.z, EET_T_DOUBLE);
#endif #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); EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Edje_Part_Image_Id);
_edje_edd_edje_part_image_id = _edje_edd_edje_part_image_id =

View File

@ -73,8 +73,8 @@
* set_state(part_id, state[], Float:state_val) * set_state(part_id, state[], Float:state_val)
* get_state(part_id, dst[], maxlen, &Float:val) * get_state(part_id, dst[], maxlen, &Float:val)
* set_tween_state(part_id, Float:tween, state1[], Float:state1_val, state2[], Float:state2_val) * set_tween_state(part_id, Float:tween, state1[], Float:state1_val, state2[], Float:state2_val)
* play_sample(sample_name, speed) * play_sample(sample_name, speed, ...)
* play_tone(tone_name, duration) * play_tone(tone_name, duration, ...)
* run_program(program_id) * run_program(program_id)
* Direction:get_drag_dir(part_id) * Direction:get_drag_dir(part_id)
* get_drag(part_id, &Float:dx, &Float:&dy) * 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; Edje *ed;
char *sample_name = NULL; char *sample_name = NULL;
float speed = 1.0; 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); ed = embryo_program_data_get(ep);
GETSTR(sample_name, params[1]); GETSTR(sample_name, params[1]);
if ((!sample_name)) return 0; if ((!sample_name)) return 0;
speed = EMBRYO_CELL_TO_FLOAT(params[2]); 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; return 0;
} }
@ -931,13 +936,18 @@ _edje_embryo_fn_play_tone(Embryo_Program *ep, Embryo_Cell *params)
Edje *ed; Edje *ed;
char *tone_name = NULL; char *tone_name = NULL;
float duration = 0.1; 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); ed = embryo_program_data_get(ep);
GETSTR(tone_name, params[1]); GETSTR(tone_name, params[1]);
if ((!tone_name)) return 0; if ((!tone_name)) return 0;
duration = EMBRYO_CELL_TO_FLOAT(params[2]); 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; return 0;
} }

View File

@ -80,7 +80,8 @@ eet_snd_file_tell(void *data, Eo *eo_obj EINA_UNUSED)
return vf->offset; return vf->offset;
} }
static void _free(void *data) static void
_free(void *data)
{ {
struct _edje_multisense_eet_data *eet_data = data; struct _edje_multisense_eet_data *eet_data = data;
@ -90,18 +91,58 @@ static void _free(void *data)
free(data); free(data);
outs--; 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 #endif
Eina_Bool EAPI void
_edje_multisense_internal_sound_sample_play(Edje *ed, const char *sample_name, const double speed) edje_audio_channel_mute_set(Edje_Channel channel, Eina_Bool mute)
{ {
#ifdef ENABLE_MULTISENSE #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, int channel)
{
#ifdef ENABLE_MULTISENSE
Eo *in; Eo *in;
Edje_Sound_Sample *sample; Edje_Sound_Sample *sample;
char snd_id_str[255]; char snd_id_str[255];
int i; int i;
Eina_Bool ret; Eina_Bool ret;
if (_channel_mute(ed, channel)) return EINA_FALSE;
if (outfail) return EINA_FALSE; if (outfail) return EINA_FALSE;
if (!sample_name) if (!sample_name)
@ -189,12 +230,13 @@ _edje_multisense_internal_sound_sample_play(Edje *ed, const char *sample_name, c
(void) ed; (void) ed;
(void) sample_name; (void) sample_name;
(void) speed; (void) speed;
(void) channel;
return EINA_FALSE; return EINA_FALSE;
#endif #endif
} }
Eina_Bool 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 #ifdef ENABLE_MULTISENSE
unsigned int i; unsigned int i;
@ -208,6 +250,8 @@ _edje_multisense_internal_sound_tone_play(Edje *ed, const char *tone_name, const
return EINA_FALSE; return EINA_FALSE;
} }
if (_channel_mute(ed, channel)) return EINA_FALSE;
if (outfail) return EINA_FALSE; if (outfail) return EINA_FALSE;
if ((!ed) || (!ed->file) || (!ed->file->sound_dir)) 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) ed;
(void) duration; (void) duration;
(void) tone_name; (void) tone_name;
(void) channel;
return EINA_FALSE; return EINA_FALSE;
#endif #endif

View File

@ -676,7 +676,7 @@ struct _Edje_Program /* a conditional program to be run */
double z; double z;
} physics; } physics;
#endif #endif
unsigned char channel;
Eina_Bool exec : 1; 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_init(void);
void _edje_multisense_shutdown(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_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); 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); void _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *state);

View File

@ -877,12 +877,12 @@ low_mem_current:
case EDJE_ACTION_TYPE_SOUND_SAMPLE: case EDJE_ACTION_TYPE_SOUND_SAMPLE:
if (_edje_block_break(ed)) if (_edje_block_break(ed))
goto break_prog; 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; break;
case EDJE_ACTION_TYPE_SOUND_TONE: case EDJE_ACTION_TYPE_SOUND_TONE:
if (_edje_block_break(ed)) if (_edje_block_break(ed))
goto break_prog; 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; break;
case EDJE_ACTION_TYPE_PARAM_COPY: case EDJE_ACTION_TYPE_PARAM_COPY:
{ {