cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=05a8f2eac620abdbf1406c3e1cb078efebbe117e

commit 05a8f2eac620abdbf1406c3e1cb078efebbe117e
Author: Kateryna Fesyna <[email protected]>
Date:   Tue Jun 10 17:14:59 2014 +0200

    edje: Edje_Edit - add edje_edit_sound_sample_del() function that provides 
the ability to delete sound sample from collection.
    
    Summary:
    Added new function that allows user to delete sound sample from collection.
    After successfull deletion this function will check if this sound was in 
use in any
    PLAY_SAMPLE action in any program of current collections groups. If such 
actions
    are found, they will be deleted.
    Also, this commit fixes code generation on edj-file saving:
    - sound block generation is added.
    - PLAY_SAMPLE and PLAY_TONE actions code generation is added.
    
    @festure
    
    Reviewers: cedric, Hermet, seoz, raster
    
    CC: reutskiy.v.v, cedric
    
    Differential Revision: https://phab.enlightenment.org/D986
    
    Signed-off-by: Cedric BAIL <[email protected]>
---
 src/lib/edje/Edje_Edit.h |  13 +++
 src/lib/edje/edje_edit.c | 233 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 246 insertions(+)

diff --git a/src/lib/edje/Edje_Edit.h b/src/lib/edje/Edje_Edit.h
index 3b59ec6..6fcd59d 100644
--- a/src/lib/edje/Edje_Edit.h
+++ b/src/lib/edje/Edje_Edit.h
@@ -3444,6 +3444,19 @@ EAPI Eina_List * 
edje_edit_sounds_samples_get(Evas_Object *obj);
  */
 EAPI Eina_List * edje_edit_sounds_tones_get(Evas_Object *obj);
 
+/** Delete sound sample from the collection
+ *
+ * Deletes sound sample from collection by its name. After successfull deletion
+ * all PLAY_SAMPLE actions in all programs of all groups of current collection
+ * that use deleted sound will be deleted.
+ *
+ * @param obj Object being edited.
+ * @param name The name of the sound file to be deleted from the edje.
+ *
+ * @return EINA_TRUE if successful, EINA_FALSE otherwise.
+ */
+EAPI Eina_Bool edje_edit_sound_sample_del(Evas_Object *obj, const char *name);
+
 //@}
 
/******************************************************************************/
 /*************************   SPECTRUM API   
***********************************/
diff --git a/src/lib/edje/edje_edit.c b/src/lib/edje/edje_edit.c
index a2ebcf8..2ae2bbf 100644
--- a/src/lib/edje/edje_edit.c
+++ b/src/lib/edje/edje_edit.c
@@ -907,6 +907,134 @@ edje_edit_compiler_get(Evas_Object *obj)
 }
 
 /****************/
+/*  SOUNDS API  */
+/****************/
+
+static Eina_Bool _edje_edit_collection_save(Eet_File *eetf, 
Edje_Part_Collection *epc);
+
+EAPI Eina_Bool
+edje_edit_sound_sample_del(Evas_Object *obj, const char* name)
+{
+   Edje_Sound_Sample *sound_sample = NULL;
+   unsigned int i = 0;
+
+   GET_ED_OR_RETURN(EINA_FALSE);
+
+   if (!name) return EINA_FALSE;
+   if (!ed->file) return EINA_FALSE;
+   if (!ed->path) return EINA_FALSE;
+
+   if ((!ed->file->sound_dir) || (!ed->file->sound_dir->samples))
+     {
+        WRN("Unable to delete sample \"%s\". The samples list is empty.", 
name);
+        return EINA_FALSE;
+     }
+
+   for (i = 0; i < ed->file->sound_dir->samples_count; ++i)
+     {
+        sound_sample = ed->file->sound_dir->samples + i;
+        if (!strcmp(name, sound_sample->name))
+           break;
+     }
+   if (i == ed->file->sound_dir->samples_count)
+     {
+        WRN("Unable to delete sample \"%s\". It does not exist.", name);
+        return EINA_FALSE;
+     }
+
+   {
+      char sample[PATH_MAX];
+      Eet_File *eetf;
+
+      Edje_Sound_Sample *sound_sample_last;
+
+      eetf = eet_open(ed->path, EET_FILE_MODE_READ_WRITE);
+      if (!eetf)
+        {
+           WRN("Unable to open \"%s\" for writing output", ed->path);
+           return EINA_FALSE;
+        }
+
+      snprintf(sample, sizeof(sample), "edje/sounds/%i", sound_sample->id);
+
+      if (eet_delete(eetf, sample) <= 0)
+        {
+           WRN("Unable to delete \"%s\" sound", sample);
+           eet_close(eetf);
+           return EINA_FALSE;
+        }
+
+      sound_sample_last = ed->file->sound_dir->samples +
+                          ed->file->sound_dir->samples_count - 1;
+
+      if (sound_sample_last->id != sound_sample->id)
+        *sound_sample = *sound_sample_last;
+
+      _edje_if_string_free(ed, sound_sample->name);
+      --ed->file->sound_dir->samples_count;
+
+      ed->file->sound_dir->samples = realloc(ed->file->sound_dir->samples,
+                                             sizeof(Edje_Sound_Sample) *
+                                             
ed->file->sound_dir->samples_count);
+
+      Eina_Iterator *it = eina_hash_iterator_data_new(ed->file->collection);
+      Edje_Part_Collection_Directory_Entry *pce;
+
+      EINA_ITERATOR_FOREACH(it, pce)
+        {
+           Eina_Bool is_collection_changed = EINA_FALSE;
+           int i;
+
+           if (pce->group_alias)
+             continue;
+
+           Evas_Object *obj = edje_edit_object_add(ed->base->evas);
+           if (!edje_object_file_set(obj, ed->file->path, pce->entry))
+             continue;
+
+           Eina_List *programs_list = edje_edit_programs_list_get(obj);
+           if (!programs_list)
+             continue;
+             
+             GET_ED_OR_RETURN(EINA_FALSE);
+
+           for (i = 0; i < ed->collection->patterns.table_programs_size; i++)
+             {
+                Edje_Program *program;
+
+                program = ed->collection->patterns.table_programs[i];
+                if ((program->action == EDJE_ACTION_TYPE_SOUND_SAMPLE) &&
+                    (!strcmp(program->sample_name, name)))
+                  {
+                     program->action = EDJE_ACTION_TYPE_NONE;
+                     program->duration = 0;
+                     program->channel = EDJE_CHANNEL_EFFECT;
+                     _edje_if_string_free(ed, program->sample_name);
+                     program->sample_name = NULL;
+                     is_collection_changed = EINA_TRUE;
+                  }
+             }
+           if (is_collection_changed)
+             {
+                _edje_edit_collection_save(eetf, ed->collection);
+             }
+        }
+
+      if (!_edje_edit_edje_file_save(eetf, ed->file))
+        {
+           eet_close(eetf);
+           return EINA_FALSE;
+        }
+      eet_close(eetf);
+   }
+
+   GET_EED_OR_RETURN(EINA_FALSE);
+   _edje_edit_flag_script_dirty(eed, EINA_TRUE);
+
+   return EINA_TRUE;
+}
+
+/****************/
 /*  GROUPS API  */
 /****************/
 
@@ -7886,6 +8014,54 @@ _edje_generate_source_of_program(Evas_Object *obj, const 
char *program, Eina_Str
                }
           }
         break;
+     case EDJE_ACTION_TYPE_SOUND_SAMPLE:
+       {
+          BUF_APPEND(I4"action: PLAY_SAMPLE ");
+          BUF_APPENDF("\"%s\" %.000f", epr->sample_name, epr->speed);
+          switch (epr->channel)
+            {
+             case EDJE_CHANNEL_BACKGROUND:
+               {
+                  BUF_APPEND(" BACKGROUND");
+                  break;
+               }
+             case EDJE_CHANNEL_MUSIC:
+               {
+                  BUF_APPEND(" MUSIC");
+                  break;
+               }
+             case EDJE_CHANNEL_FOREGROUND:
+               {
+                  BUF_APPEND(" FOREGROUND");
+                  break;
+               }
+             case EDJE_CHANNEL_INTERFACE:
+               {
+                  BUF_APPEND(" INTERFACE");
+                  break;
+               }
+             case EDJE_CHANNEL_INPUT:
+               {
+                  BUF_APPEND(" INPUT");
+                  break;
+               }
+             case EDJE_CHANNEL_ALERT:
+               {
+                  BUF_APPEND(" ALERT");
+                  break;
+               }
+             default:
+               break;
+            }
+          BUF_APPENDF(";\n");
+          break;
+       }
+     case EDJE_ACTION_TYPE_SOUND_TONE:
+       {
+          BUF_APPEND(I4"action: PLAY_TONE ");
+          BUF_APPENDF("\"%s\" %.000f\n;", epr->tone_name, epr->duration);
+          break;
+       }
      //TODO Support Drag
      //~ case EDJE_ACTION_TYPE_DRAG_VAL_SET:
        //~ eina_strbuf_append(buf, I4"action: DRAG_VAL_SET TODO;\n");
@@ -8442,6 +8618,57 @@ _edje_generate_source_of_part(Evas_Object *obj, 
Edje_Part *ep, Eina_Strbuf *buf)
    return ret;
 }
 
+static void
+_edje_generate_source_of_sounds(Edje_Sound_Directory *sound_directory, 
Eina_Strbuf *buf)
+{
+   unsigned int i = 0;
+   Eina_Bool ret = EINA_TRUE;
+   Edje_Sound_Sample *current_sample = sound_directory->samples;
+   Edje_Sound_Tone *current_tone = sound_directory->tones;
+   BUF_APPEND(I1"sounds {\n");
+
+
+   for (i = 0; i < sound_directory->samples_count; i++, current_sample++)
+     {
+        BUF_APPEND(I2"sample {\n");
+        BUF_APPENDF(I3"name: \"%s\" ", current_sample->name);
+        switch (current_sample->compression)
+          {
+           case EDJE_SOUND_SOURCE_TYPE_INLINE_RAW:
+             {
+                BUF_APPEND("RAW;\n");
+                break;
+             }
+           case EDJE_SOUND_SOURCE_TYPE_INLINE_COMP:
+             {
+                BUF_APPEND("COMP;\n");
+                break;
+             }
+           case EDJE_SOUND_SOURCE_TYPE_INLINE_LOSSY:
+             {
+                BUF_APPENDF("LOSSY %f;\n", current_sample->quality);
+                break;
+             }
+           case EDJE_SOUND_SOURCE_TYPE_INLINE_AS_IS:
+             {
+                BUF_APPEND("AS_IS;\n");
+                break;
+             }
+           default:
+             break;
+          }
+        BUF_APPENDF(I3"source: \"%s\";\n", current_sample->snd_src);
+        BUF_APPEND(I2"}\n");
+     }
+   for (i = 0; i < sound_directory->tones_count ; i++, current_tone++)
+     {
+        BUF_APPEND(I2"tone: ");
+        BUF_APPENDF("\"%s\" %d;\n", current_tone->name, current_tone->value);
+     }
+
+   BUF_APPEND(I1"}\n");
+}
+
 static Eina_Bool
 _edje_generate_source_of_group(Edje *ed, Edje_Part_Collection_Directory_Entry 
*pce, Eina_Strbuf *buf)
 {
@@ -8722,6 +8949,12 @@ _edje_generate_source(Evas_Object *obj)
         Edje_Part_Collection_Directory_Entry *pce;
         BUF_APPEND("collections {\n");
 
+        /* Sounds */
+        if (ed->file->sound_dir)
+          {
+             _edje_generate_source_of_sounds(ed->file->sound_dir, buf);
+          }
+
         it = eina_hash_iterator_data_new(ed->file->collection);
 
         if (!it)

-- 


Reply via email to