Multisense example

This is a simple example in which a rect is created and sound and tone are played on mouse down event.

Focusing on the creation of sample and tone. It should be noted that creation of sample sound is from any supported (sndfile lib) audio file, tone from of specific audible frequency range are controlled by the theme:

The full source code follows:

#include <Eina.h>
#include <Evas.h>
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Edje.h>
#ifndef PACKAGE_DATA_DIR
#define PACKAGE_DATA_DIR "."
#endif
#define WIDTH 300
#define HEIGHT 300
static Evas_Object *create_my_group(Evas *canvas)
{
Evas_Object *edje;
edje = edje_object_add(canvas);
if (!edje)
{
EINA_LOG_CRIT("could not create edje object!");
return NULL;
}
if (!edje_object_file_set(edje, PACKAGE_DATA_DIR"/multisense.edj",
"example_group"))
{
int err = edje_object_load_error_get(edje);
const char *errmsg = edje_load_error_str(err);
EINA_LOG_ERR("could not load 'example_group' from multisense.edj: %s",
errmsg);
evas_object_del(edje);
return NULL;
}
evas_object_move(edje, 0, 0);
evas_object_resize(edje, WIDTH, HEIGHT);
evas_object_show(edje);
return edje;
}
int main()
{
Ecore_Evas *window;
Evas *canvas;
Evas_Object *edje;
ecore_evas_init();
edje_init();
window = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
if (!window)
{
EINA_LOG_CRIT("could not create window.");
return -1;
}
canvas = ecore_evas_get(window);
edje = create_my_group(canvas);
if (!edje)
return -2;
ecore_evas_show(window);
ecore_main_loop_begin();
evas_object_del(edje);
ecore_evas_free(window);
edje_shutdown();
ecore_evas_shutdown();
return 0;
}
Ecore_Evas.h
Evas wrapper functions.
Edje.h
Edje Graphical Design Library.
Eina.h
Eina Utility library.
ecore_evas_init
EAPI int ecore_evas_init(void)
Inits the Ecore_Evas system.
Definition ecore_evas.c:608
ecore_evas_show
EAPI void ecore_evas_show(Ecore_Evas *ee)
Shows an Ecore_Evas' window.
Definition ecore_evas.c:1494
ecore_evas_get
EAPI Evas * ecore_evas_get(const Ecore_Evas *ee)
Gets an Ecore_Evas's Evas.
Definition ecore_evas.c:1314
ecore_evas_new
EAPI Ecore_Evas * ecore_evas_new(const char *engine_name, int x, int y, int w, int h, const char *extra_options)
Creates a new Ecore_Evas based on engine name and common parameters.
Definition ecore_evas.c:1053
ecore_evas_shutdown
EAPI int ecore_evas_shutdown(void)
Shuts down the Ecore_Evas system.
Definition ecore_evas.c:672
ecore_evas_free
EAPI void ecore_evas_free(Ecore_Evas *ee)
Frees an Ecore_Evas.
Definition ecore_evas.c:1097
ecore_main_loop_begin
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition ecore_main.c:1311
edje_shutdown
int edje_shutdown(void)
Shuts down the Edje library.
Definition edje_main.c:262
edje_init
int edje_init(void)
Initializes the Edje library.
Definition edje_main.c:35
edje_object_load_error_get
Edje_Load_Error edje_object_load_error_get(const Eo *obj)
Gets the (last) file loading error for a given Edje object.
Definition edje_legacy.c:15
edje_object_add
Evas_Object * edje_object_add(Evas *evas)
Instantiates a new Edje object.
Definition edje_smart.c:22
edje_load_error_str
const char * edje_load_error_str(Edje_Load_Error error)
Converts the given Edje file load error code into a string describing it in English.
Definition edje_load.c:108
edje_object_file_set
Eina_Bool edje_object_file_set(Evas_Object *obj, const char *file, const char *group)
Sets the EDJ file (and group within it) to load an Edje object's contents from.
Definition edje_smart.c:467
EINA_LOG_ERR
#define EINA_LOG_ERR(fmt,...)
Logs a message with level ERROR on the default domain with the specified format.
Definition eina_log.h:376
EINA_LOG_CRIT
#define EINA_LOG_CRIT(fmt,...)
Logs a message with level CRITICAL on the default domain with the specified format.
Definition eina_log.h:365
Evas
Eo Evas
An opaque handle to an Evas canvas.
Definition Evas_Common.h:163
evas_object_show
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition evas_object_main.c:1814
evas_object_del
EVAS_API void evas_object_del(Evas_Object *obj)
Marks the given Evas object for deletion (when Evas will free its memory).
Definition evas_object_main.c:928
evas_object_move
EVAS_API void evas_object_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
Move the given Evas object to the given location inside its canvas' viewport.
Definition evas_object_main.c:1171
Evas_Object
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition Evas_Common.h:185
evas_object_resize
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition evas_object_main.c:1236
collections {
sounds {
sample {
name: "sound_name1" RAW;
source: "duck.wav";
}
tone: "tone-name" 2600;
}
group {
name: "example_group";
parts {
part {
name: "sample_bg";
type: RECT;
mouse_events: 1;
description {
state: "default" 0.0;
min: 300 150;
max: 300 150;
color: 200 200 200 100;
align: 0.5 0.0;
rel1 {
relative: 0.0 0.0;
}
}
}
part {
name: "sample_text";
type: TEXT;
mouse_events: 1;
repeat_events: 1;
description {
state: "default" 0.0;
rel1.to: "sample_bg";
rel2.to: "sample_bg";
text {
font: "Sans";
size: 20;
text: "Play Sound Sample";
}
}
}
part {
name: "tone_bg";
type: RECT;
mouse_events: 1;
description {
state: "default" 0.0;
min: 300 150;
max: 300 150;
align: 0.5 0.0;
color: 180 180 180 100;
rel1 {
relative: 0.0 1.0;
to: "sample_bg";
}
}
}
part {
name: "tone_text";
type: TEXT;
mouse_events: 1;
repeat_events: 1;
description {
state: "default" 0.0;
rel1.to: "tone_bg";
rel2.to: "tone_bg";
text {
font: "Sans";
size: 20;
text: "Play Tone";
}
}
}
programs {
program {
name: "click_sample1";
signal: "mouse,down,1";
source: "sample_bg";
action: PLAY_SAMPLE "sound_name1" 1.0;
}
program {
name: "click_tone";
signal: "mouse,down,1";
source: "tone_bg";
action: PLAY_TONE "tone-name" 0.1;
}
}
}
}
}