You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

160 lines
7.0 KiB

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
  2. *
  3. * Copyright (C) 2014 Michal Ratajsky <michal.ratajsky@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  18. *
  19. */
  20. #include "config.h"
  21. #include <glib.h>
  22. #include <glib/gi18n.h>
  23. #include <gtk/gtk.h>
  24. #include <libmatemixer/matemixer.h>
  25. #include "gvc-utils.h"
  26. /* libcanberra requires a PulseAudio channel name to be given to its
  27. * CA_PROP_CANBERRA_FORCE_CHANNEL property.
  28. *
  29. * The strings here are copied from PulseAudio source code to avoid depending
  30. * on libpulse. */
  31. static const gchar *pulse_position[MATE_MIXER_CHANNEL_MAX] = {
  32. [MATE_MIXER_CHANNEL_MONO] = "mono",
  33. [MATE_MIXER_CHANNEL_FRONT_LEFT] = "front-left",
  34. [MATE_MIXER_CHANNEL_FRONT_RIGHT] = "front-right",
  35. [MATE_MIXER_CHANNEL_FRONT_CENTER] = "front-center",
  36. [MATE_MIXER_CHANNEL_LFE] = "lfe",
  37. [MATE_MIXER_CHANNEL_BACK_LEFT] = "rear-left",
  38. [MATE_MIXER_CHANNEL_BACK_RIGHT] = "rear-right",
  39. [MATE_MIXER_CHANNEL_BACK_CENTER] = "rear-center",
  40. [MATE_MIXER_CHANNEL_FRONT_LEFT_CENTER] = "front-left-of-center",
  41. [MATE_MIXER_CHANNEL_FRONT_RIGHT_CENTER] = "front-right-of-center",
  42. [MATE_MIXER_CHANNEL_SIDE_LEFT] = "side-left",
  43. [MATE_MIXER_CHANNEL_SIDE_RIGHT] = "side-right",
  44. [MATE_MIXER_CHANNEL_TOP_FRONT_LEFT] = "top-front-left",
  45. [MATE_MIXER_CHANNEL_TOP_FRONT_RIGHT] = "top-front-right",
  46. [MATE_MIXER_CHANNEL_TOP_FRONT_CENTER] = "top-front-center",
  47. [MATE_MIXER_CHANNEL_TOP_CENTER] = "top-center",
  48. [MATE_MIXER_CHANNEL_TOP_BACK_LEFT] = "top-rear-left",
  49. [MATE_MIXER_CHANNEL_TOP_BACK_RIGHT] = "top-rear-right",
  50. [MATE_MIXER_CHANNEL_TOP_BACK_CENTER] = "top-rear-center"
  51. };
  52. static const gchar *pretty_position[MATE_MIXER_CHANNEL_MAX] = {
  53. [MATE_MIXER_CHANNEL_UNKNOWN] = N_("Unknown"),
  54. /* Speaker channel names */
  55. [MATE_MIXER_CHANNEL_MONO] = N_("Mono"),
  56. [MATE_MIXER_CHANNEL_FRONT_LEFT] = N_("Front Left"),
  57. [MATE_MIXER_CHANNEL_FRONT_RIGHT] = N_("Front Right"),
  58. [MATE_MIXER_CHANNEL_FRONT_CENTER] = N_("Front Center"),
  59. [MATE_MIXER_CHANNEL_LFE] = N_("LFE"),
  60. [MATE_MIXER_CHANNEL_BACK_LEFT] = N_("Rear Left"),
  61. [MATE_MIXER_CHANNEL_BACK_RIGHT] = N_("Rear Right"),
  62. [MATE_MIXER_CHANNEL_BACK_CENTER] = N_("Rear Center"),
  63. [MATE_MIXER_CHANNEL_FRONT_LEFT_CENTER] = N_("Front Left of Center"),
  64. [MATE_MIXER_CHANNEL_FRONT_RIGHT_CENTER] = N_("Front Right of Center"),
  65. [MATE_MIXER_CHANNEL_SIDE_LEFT] = N_("Side Left"),
  66. [MATE_MIXER_CHANNEL_SIDE_RIGHT] = N_("Side Right"),
  67. [MATE_MIXER_CHANNEL_TOP_FRONT_LEFT] = N_("Top Front Left"),
  68. [MATE_MIXER_CHANNEL_TOP_FRONT_RIGHT] = N_("Top Front Right"),
  69. [MATE_MIXER_CHANNEL_TOP_FRONT_CENTER] = N_("Top Front Center"),
  70. [MATE_MIXER_CHANNEL_TOP_CENTER] = N_("Top Center"),
  71. [MATE_MIXER_CHANNEL_TOP_BACK_LEFT] = N_("Top Rear Left"),
  72. [MATE_MIXER_CHANNEL_TOP_BACK_RIGHT] = N_("Top Rear Right"),
  73. [MATE_MIXER_CHANNEL_TOP_BACK_CENTER] = N_("Top Rear Center")
  74. };
  75. const gchar *
  76. gvc_channel_position_to_pulse_string (MateMixerChannelPosition position)
  77. {
  78. g_return_val_if_fail (position >= 0 && position < MATE_MIXER_CHANNEL_MAX, NULL);
  79. return pulse_position[position];
  80. }
  81. const gchar *
  82. gvc_channel_position_to_pretty_string (MateMixerChannelPosition position)
  83. {
  84. g_return_val_if_fail (position >= 0 && position < MATE_MIXER_CHANNEL_MAX, NULL);
  85. return pretty_position[position];
  86. }
  87. const gchar *
  88. gvc_channel_map_to_pretty_string (MateMixerStreamControl *control)
  89. {
  90. g_return_val_if_fail (MATE_MIXER_IS_STREAM_CONTROL (control), NULL);
  91. #define HAS_POSITION(p) (mate_mixer_stream_control_has_channel_position (control, (p)))
  92. /* Modeled after PulseAudio 5.0, probably could be extended with other combinations */
  93. switch (mate_mixer_stream_control_get_num_channels (control)) {
  94. case 1:
  95. if (HAS_POSITION (MATE_MIXER_CHANNEL_MONO))
  96. return _("Mono");
  97. break;
  98. case 2:
  99. if (HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_LEFT) &&
  100. HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_RIGHT))
  101. return _("Stereo");
  102. break;
  103. case 4:
  104. if (HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_LEFT) &&
  105. HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_RIGHT) &&
  106. HAS_POSITION (MATE_MIXER_CHANNEL_BACK_LEFT) &&
  107. HAS_POSITION (MATE_MIXER_CHANNEL_BACK_RIGHT))
  108. return _("Surround 4.0");
  109. break;
  110. case 5:
  111. if (HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_LEFT) &&
  112. HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_RIGHT) &&
  113. HAS_POSITION (MATE_MIXER_CHANNEL_BACK_LEFT) &&
  114. HAS_POSITION (MATE_MIXER_CHANNEL_BACK_RIGHT)) {
  115. if (HAS_POSITION (MATE_MIXER_CHANNEL_LFE))
  116. return _("Surround 4.1");
  117. if (HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_CENTER))
  118. return _("Surround 5.0");
  119. }
  120. break;
  121. case 6:
  122. if (HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_LEFT) &&
  123. HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_RIGHT) &&
  124. HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_CENTER) &&
  125. HAS_POSITION (MATE_MIXER_CHANNEL_BACK_LEFT) &&
  126. HAS_POSITION (MATE_MIXER_CHANNEL_BACK_RIGHT) &&
  127. HAS_POSITION (MATE_MIXER_CHANNEL_LFE))
  128. return _("Surround 5.1");
  129. break;
  130. case 8:
  131. if (HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_LEFT) &&
  132. HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_RIGHT) &&
  133. HAS_POSITION (MATE_MIXER_CHANNEL_FRONT_CENTER) &&
  134. HAS_POSITION (MATE_MIXER_CHANNEL_BACK_LEFT) &&
  135. HAS_POSITION (MATE_MIXER_CHANNEL_BACK_RIGHT) &&
  136. HAS_POSITION (MATE_MIXER_CHANNEL_SIDE_LEFT) &&
  137. HAS_POSITION (MATE_MIXER_CHANNEL_SIDE_RIGHT) &&
  138. HAS_POSITION (MATE_MIXER_CHANNEL_LFE))
  139. return _("Surround 7.1");
  140. break;
  141. }
  142. #undef HAS_POSITION
  143. return NULL;
  144. }