Piano / src / player /

piano-impl-player.c

  1. /*
  2. * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the License);
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16.  
  17. #include "player/piano-player.h"
  18. #include "logger.h"
  19. #include "config.h"
  20. #include "piano-structs.h"
  21.  
  22. void piano_note_player_init(void *data)
  23. {
  24. RETM_IF(!data, "data is NULL");
  25.  
  26. note_struct *note = (note_struct *)data;
  27.  
  28. player_create(&(note->player));
  29. }
  30.  
  31. void piano_players_destroy(void *data)
  32. {
  33. RETM_IF(!data, "data is NULL");
  34.  
  35. app_data *ad = (app_data *)data;
  36.  
  37. Eina_List *l = NULL;
  38. note_struct *note = NULL;
  39. EINA_LIST_FOREACH(ad->buttonList, l, note) {
  40. player_unprepare(note->player);
  41. player_destroy(note->player);
  42. note->player = NULL;
  43. }
  44. }
  45.  
  46. void piano_player_play(void *data)
  47. {
  48. RETM_IF(!data, "data is NULL");
  49. note_struct *note = (note_struct *) data;
  50.  
  51. piano_player_stop(note);
  52.  
  53. player_start(note->player);
  54. }
  55.  
  56. void piano_player_stop(void *data)
  57. {
  58. RETM_IF(!data, "data is NULL");
  59. note_struct *note = (note_struct *) data;
  60.  
  61. player_state_e state;
  62. player_get_state(note->player, &state);
  63. if (state == PLAYER_STATE_PLAYING) {
  64. player_stop(note->player);
  65. }
  66. }
  67.  
  68. void piano_note_player_prepare(void *data)
  69. {
  70. RETM_IF(!data, "data is NULL");
  71. note_struct *note = (note_struct *) data;
  72.  
  73. char sound_path[PATH_MAX] = {'\0'};
  74. snprintf(sound_path, PATH_MAX, "%s/%s", get_path(SNDPATH), note->sound_name);
  75.  
  76. int ret = player_set_uri(note->player, sound_path);
  77.  
  78. RETM_IF(ret != PLAYER_ERROR_NONE, "ret=%d, note->player=%p", ret, note->player);
  79.  
  80. player_prepare(note->player);
  81. }