Commit 1aaba1ac authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Add equalizer

parent aadc8d7a
......@@ -119,6 +119,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/medialibrary/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/emotion/src/lib}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/vlc/include}&quot;"/>
</option>
<option id="sbi.gnu.cpp.compiler.option.frameworks.core.237121513" name="Tizen-Frameworks" superClass="sbi.gnu.cpp.compiler.option.frameworks.core" valueType="userObjs">
<listOptionValue builtIn="false" value="Native_API"/>
......@@ -225,6 +226,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/medialibrary/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/emotion/src/lib}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/vlc/include}&quot;"/>
</option>
<option id="sbi.gnu.c.compiler.option.frameworks.core.1431397869" name="Tizen-Frameworks" superClass="sbi.gnu.c.compiler.option.frameworks.core" valueType="userObjs">
<listOptionValue builtIn="false" value="Native_API"/>
......@@ -411,6 +413,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/medialibrary/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/emotion/src/lib}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/vlc/include}&quot;"/>
</option>
<option id="sbi.gnu.cpp.compiler.option.frameworks.core.58847965" name="Tizen-Frameworks" superClass="sbi.gnu.cpp.compiler.option.frameworks.core" valueType="userObjs">
<listOptionValue builtIn="false" value="Native_API"/>
......@@ -517,6 +520,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/medialibrary/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/emotion/src/lib}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/vlc/include}&quot;"/>
</option>
<option id="sbi.gnu.c.compiler.option.frameworks.core.2015291070" name="Tizen-Frameworks" superClass="sbi.gnu.c.compiler.option.frameworks.core" valueType="userObjs">
<listOptionValue builtIn="false" value="Native_API"/>
......
......@@ -118,6 +118,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/medialibrary/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/emotion/src/lib}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/vlc/include}&quot;"/>
</option>
<option id="sbi.gnu.cpp.compiler.option.frameworks.core.237121513" name="Tizen-Frameworks" superClass="sbi.gnu.cpp.compiler.option.frameworks.core" valueType="userObjs">
<listOptionValue builtIn="false" value="Native_API"/>
......@@ -223,6 +224,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/medialibrary/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/emotion/src/lib}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/vlc/include}&quot;"/>
</option>
<option id="sbi.gnu.c.compiler.option.frameworks.core.1431397869" name="Tizen-Frameworks" superClass="sbi.gnu.c.compiler.option.frameworks.core" valueType="userObjs">
<listOptionValue builtIn="false" value="Native_API"/>
......@@ -408,6 +410,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/medialibrary/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/emotion/src/lib}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/vlc/include}&quot;"/>
</option>
<option id="sbi.gnu.cpp.compiler.option.frameworks.core.58847965" name="Tizen-Frameworks" superClass="sbi.gnu.cpp.compiler.option.frameworks.core" valueType="userObjs">
<listOptionValue builtIn="false" value="Native_API"/>
......@@ -513,6 +516,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/medialibrary/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/emotion/src/lib}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/vlc/include}&quot;"/>
</option>
<option id="sbi.gnu.c.compiler.option.frameworks.core.2015291070" name="Tizen-Frameworks" superClass="sbi.gnu.c.compiler.option.frameworks.core" valueType="userObjs">
<listOptionValue builtIn="false" value="Native_API"/>
......
......@@ -998,3 +998,15 @@ playback_service_current_file_path_get(playback_service *p_ps)
{
return emotion_object_file_get(p_ps->p_e);
}
void
playback_service_eq_set(playback_service* p_ps, float f_preamp, unsigned int i_nb_bands, float* f_bands )
{
emotion_object_equalizer_set( p_ps->p_e, f_preamp, i_nb_bands, f_bands );
}
void
playback_service_eq_get(playback_service* p_ps, float* f_preamp, unsigned int* i_nb_bands, float** f_bands )
{
emotion_object_equalizer_get( p_ps->p_e, f_preamp, i_nb_bands, f_bands );
}
......@@ -208,4 +208,10 @@ playback_service_is_background_playback(playback_service *p_ps);
const char*
playback_service_current_file_path_get(playback_service *p_ps);
void
playback_service_eq_set(playback_service* p_ps, float f_preamp, unsigned int i_nb_bands, float* f_bands );
void
playback_service_eq_get(playback_service* p_ps, float* f_preamp, unsigned int* i_nb_bands, float** f_bands );
#endif /* PLAYBACK_SERVICE_H */
......@@ -36,12 +36,14 @@
#include "ui/utils.h"
#include "ui/views/list_view.h"
#include "ui/playlists.h"
#include "ui/equalizer.h"
struct audio_player {
interface *intf;
playback_service *p_ps;
playback_service_cbs_id *p_ps_cbs_id;
playlists *p_playlists;
equalizer* p_equalizer;
bool save_state, shuffle_state, playlist_state, more_state, fs_state;
double slider_event_time;
......@@ -92,6 +94,7 @@ typedef struct more_menu {
#define MORE_SPEED 2
#define MORE_SLEEP 3
#define MORE_PLAYLISTS 4
#define MORE_EQUALIZER 5
#define MORE_END -1
more_menu more_menu_list[] = {
......@@ -99,6 +102,7 @@ more_menu more_menu_list[] = {
{ MORE_SPEED, "Playback Speed", "ic_speed_normal.png" },
//{ MORE_SLEEP, "Sleep in", "ic_sleep_normal.png" }, // Not implemented
{ MORE_PLAYLISTS, "Add to playlist", "ic_save_normal.png" },
{ MORE_EQUALIZER, "Equalizer", "ic_equalizer_normal.png" },
{ MORE_END },
};
......@@ -291,6 +295,10 @@ popup_selected_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
if (p_media)
apd->mpd->p_playlists = playlists_popup_show(apd->mpd->intf, p_media->i_id);
break;
case MORE_EQUALIZER:
evas_object_del(apd->mpd->popup);
apd->mpd->p_equalizer = equalizer_create(apd->mpd->intf, apd->mpd->p_ps);
break;
}
evas_object_smart_callback_add(apd->mpd->popup, "block,clicked", audio_player_on_background_touched, apd->mpd);
......@@ -457,6 +465,11 @@ audio_player_handle_back_key(audio_player *mpd)
mpd->p_playlists = NULL;
return true;
}
if (mpd->p_equalizer != NULL)
{
equalizer_destroy(mpd->p_equalizer);
mpd->p_equalizer = NULL;
}
if (mpd->popup)
{
audio_player_close_popup(mpd);
......
/*****************************************************************************
* Copyright © 2015-2016 VideoLAN, VideoLabs SAS
*****************************************************************************
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* 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
* MERCHANTABILITY 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*
* By committing to this project, you allow VideoLAN and VideoLabs to relicense
* the code to a different OSI approved license, in case it is required for
* compatibility with the Store
*****************************************************************************/
#include "common.h"
#include "equalizer.h"
#include "playback_service.h"
#include <vlc/vlc.h>
struct equalizer
{
Evas_Object* p_view;
Evas_Object* p_layout;
Evas_Object* p_box;
Evas_Object* p_preset_button;
unsigned int i_nb_bands;
Evas_Object** pp_sliders;
Evas_Object* p_preamp_slider;
playback_service* p_ps;
};
static void
equalizer_dismiss_preset_popup(void *data, Evas_Object *obj, void *event_info)
{
evas_object_del(obj);
}
static void
equalizer_set_preset(equalizer* p_eq, unsigned int i_preset)
{
libvlc_equalizer_t* p_vlc_eq = libvlc_audio_equalizer_new_from_preset( i_preset );
float f_preamp = libvlc_audio_equalizer_get_preamp( p_vlc_eq );
elm_slider_value_set( p_eq->p_preamp_slider, f_preamp );
float f_bands[p_eq->i_nb_bands];
for ( unsigned int i = 0; i < p_eq->i_nb_bands; ++i )
{
f_bands[i] = libvlc_audio_equalizer_get_amp_at_index( p_vlc_eq, i );
elm_slider_value_set( p_eq->pp_sliders[i], f_bands[i] );
}
playback_service_eq_set( p_eq->p_ps, f_preamp, p_eq->i_nb_bands, f_bands );
}
static void
equalizer_preset_selected(void *data, Evas_Object *obj, void *event_info)
{
equalizer* p_eq = (equalizer*)data;
const char* psz_preset = elm_object_item_text_get(event_info);
unsigned int i_nb_presets = libvlc_audio_equalizer_get_preset_count();
for ( unsigned int i = 0; i < i_nb_presets; ++i )
{
const char* psz_name = libvlc_audio_equalizer_get_preset_name( i );
if ( strcmp( psz_name, psz_preset ) == 0 )
{
equalizer_set_preset( p_eq, i );
elm_object_text_set(p_eq->p_preset_button, psz_preset);
break;
}
}
evas_object_del(obj);
}
static void
equalizer_list_presets(void *data, Evas_Object *obj, void *event_info)
{
equalizer* p_eq = (equalizer*)data;
Evas_Object* p_parent = p_eq->p_layout;
Evas_Object* p_popup = elm_ctxpopup_add(p_parent);
elm_object_style_set(p_popup, "dropdown/list");
evas_object_smart_callback_add(p_popup, "dismissed", equalizer_dismiss_preset_popup, NULL);
evas_object_size_hint_weight_set(p_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(p_popup, EVAS_HINT_FILL, EVAS_HINT_FILL);
//add some items
unsigned int i_nb_presets = libvlc_audio_equalizer_get_preset_count();
for ( unsigned int i = 0; i < i_nb_presets; ++i )
{
const char* psz_name = libvlc_audio_equalizer_get_preset_name( i );
elm_ctxpopup_item_append(p_popup, psz_name, NULL, equalizer_preset_selected, p_eq);
}
elm_ctxpopup_direction_priority_set(p_popup, ELM_CTXPOPUP_DIRECTION_DOWN, ELM_CTXPOPUP_DIRECTION_UNKNOWN,
ELM_CTXPOPUP_DIRECTION_UNKNOWN, ELM_CTXPOPUP_DIRECTION_UNKNOWN);
//change position of the popup
Evas_Coord x, y;
evas_pointer_canvas_xy_get(evas_object_evas_get(p_parent), &x, &y);
evas_object_move(p_popup, x, y);
evas_object_show(p_popup);
}
static void
equalizer_add_presets(equalizer* p_eq)
{
Evas_Object* p_label = elm_label_add(p_eq->p_box);
elm_object_text_set(p_label, "Presets");
evas_object_size_hint_weight_set(p_label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(p_label, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(p_eq->p_box, p_label);
evas_object_show(p_label);
p_eq->p_preset_button = elm_button_add(p_eq->p_box);
elm_object_style_set(p_eq->p_preset_button, "dropdown");
evas_object_smart_callback_add(p_eq->p_preset_button, "clicked", equalizer_list_presets, p_eq);
elm_object_text_set(p_eq->p_preset_button, libvlc_audio_equalizer_get_preset_name(0));
evas_object_size_hint_weight_set(p_eq->p_preset_button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(p_eq->p_preset_button, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(p_eq->p_preset_button);
elm_box_pack_after(p_eq->p_box, p_eq->p_preset_button, p_label);
}
static void
equalizer_slider_changed_cb( void *data, Evas_Object *obj, void *event_info )
{
equalizer* p_eq = (equalizer*)data;
float f_preamp = elm_slider_value_get( p_eq->p_preamp_slider );
float f_bands[p_eq->i_nb_bands];
for ( unsigned int i = 0; i < p_eq->i_nb_bands; ++i )
{
f_bands[i] = elm_slider_value_get( p_eq->pp_sliders[i] );
}
playback_service_eq_set( p_eq->p_ps, f_preamp, p_eq->i_nb_bands, f_bands );
}
static void
equalizer_init_sliders(equalizer* p_eq)
{
Evas_Object* p_preamp_slider = p_eq->p_preamp_slider = elm_slider_add( p_eq->p_box );
elm_slider_value_set( p_preamp_slider, 0.0 );
elm_slider_min_max_set( p_preamp_slider, -20.0, 20.0 );
evas_object_size_hint_weight_set( p_preamp_slider, 0.8, EVAS_HINT_EXPAND );
evas_object_size_hint_align_set( p_preamp_slider, EVAS_HINT_FILL, EVAS_HINT_FILL );
elm_slider_unit_format_set( p_preamp_slider, "%f dB" );
elm_object_part_text_set( p_preamp_slider, "default", "Preamp" );
evas_object_smart_callback_add( p_preamp_slider, "delay,changed", equalizer_slider_changed_cb, p_eq );
evas_object_show( p_preamp_slider );
elm_box_pack_end( p_eq->p_box, p_preamp_slider );
p_eq->i_nb_bands = libvlc_audio_equalizer_get_band_count();
p_eq->pp_sliders = malloc( p_eq->i_nb_bands * sizeof( *p_eq->pp_sliders ) );
for ( unsigned int i = 0; i < p_eq->i_nb_bands; ++i )
{
float f_band_freq = libvlc_audio_equalizer_get_band_frequency( i );
char* psz_label;
if ( asprintf(&psz_label, "%f %s", f_band_freq >= 1000.f ? f_band_freq / 1000.f : f_band_freq,
f_band_freq >= 1000.f ? "kHz" : "Hz") < 0 )
continue;
Evas_Object* p_slider = p_eq->pp_sliders[i] = elm_slider_add( p_eq->p_box );
evas_object_size_hint_weight_set( p_slider, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND );
evas_object_size_hint_align_set( p_slider, EVAS_HINT_FILL, EVAS_HINT_FILL );
elm_object_part_text_set( p_slider, "default", psz_label );
elm_slider_value_set( p_slider, 0.0 );
elm_slider_min_max_set(p_slider, -20.0, 20.0);
elm_slider_unit_format_set( p_slider, "%1.2f dB" );
evas_object_smart_callback_add( p_preamp_slider, "delay,changed", equalizer_slider_changed_cb, p_eq );
evas_object_show( p_slider );
elm_box_pack_end( p_eq->p_box, p_slider );
free( psz_label );
}
}
equalizer*
equalizer_create(interface* p_intf, playback_service* p_ps)
{
equalizer* p_eq = calloc(1, sizeof(*p_eq));
if ( p_eq == NULL )
return NULL;
p_eq->p_ps = p_ps;
p_eq->p_view = elm_popup_add(intf_get_main_naviframe(p_intf));
elm_popup_orient_set(p_eq->p_view, ELM_POPUP_ORIENT_CENTER);
/* */
Evas_Object* p_layout = p_eq->p_layout = elm_layout_add(p_eq->p_view);
elm_layout_theme_set(p_layout, "layout", "application", "default");
evas_object_size_hint_weight_set(p_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(p_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
/* Create the background */
Evas_Object *bg = elm_bg_add(p_layout);
elm_bg_color_set(bg, 255, 255, 255);
evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(bg);
/* Set the background to the theme */
elm_object_part_content_set(p_layout, "elm.swallow.bg", bg);
p_eq->p_box = elm_box_add(p_layout);
evas_object_show(p_eq->p_box);
elm_object_part_content_set(p_layout, "elm.swallow.content", p_eq->p_box);
equalizer_add_presets(p_eq);
equalizer_init_sliders(p_eq);
evas_object_show(p_layout);
elm_object_content_set(p_eq->p_view, p_layout);
evas_object_show(p_eq->p_view);
return p_eq;
}
void
equalizer_destroy(equalizer* p_eq)
{
evas_object_del(p_eq->p_view);
free(p_eq->pp_sliders);
free(p_eq);
}
/*****************************************************************************
* Copyright © 2015-2016 VideoLAN, VideoLabs SAS
*****************************************************************************
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* 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
* MERCHANTABILITY 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*
* By committing to this project, you allow VideoLAN and VideoLabs to relicense
* the code to a different OSI approved license, in case it is required for
* compatibility with the Store
*****************************************************************************/
#ifndef EQUALIZER_H_
# define EQUALIZER_H_
#include "interface.h"
typedef struct equalizer equalizer;
equalizer*
equalizer_create(interface* p_intf, playback_service* p_ps);
void
equalizer_destroy(equalizer* p_eq);
#endif // EQUALIZER_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment