Changeset 1912b45 in mainline for uspace/app
- Timestamp:
- 2013-04-10T20:52:26Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5b77efc
- Parents:
- 8a7d78cc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mixerctl/mixerctl.c
r8a7d78cc r1912b45 43 43 #define DEFAULT_DEVICE "/hw/pci0/00:01.0/sb16/control" 44 44 45 /** 46 * Print volume levels on all channels on all control items. 47 * @param exch IPC exchange 48 */ 45 49 static void print_levels(async_exch_t *exch) 46 50 { … … 52 56 return; 53 57 } 54 printf("MIXER %s:\n ", name);58 printf("MIXER %s:\n\n", name); 55 59 56 60 for (unsigned i = 0; i < count; ++i) { 57 61 const char *name = NULL; 58 unsigned channels= 0;59 constint ret =60 audio_mixer_get_item_info(exch, i, &name, & channels);62 unsigned levels = 0, current = 0; 63 int ret = 64 audio_mixer_get_item_info(exch, i, &name, &levels); 61 65 if (ret != EOK) { 62 66 printf("Failed to get item %u info: %s.\n", … … 64 68 continue; 65 69 } 66 for (unsigned j = 0; j < channels; ++j) { 67 const char *chan = NULL; 68 int ret = audio_mixer_get_channel_info( 69 exch, i, j, &chan, NULL); 70 if (ret != EOK) { 71 printf( 72 "Failed to get channel %u-%u info: %s.\n", 73 i, j, str_error(ret)); 74 } 75 unsigned level = 0, max = 0; 76 ret = audio_mixer_channel_volume_get( 77 exch, i, j, &level, &max); 78 if (ret != EOK) { 79 printf("Failed to get channel %u-%u volume:" 80 " %s.\n", i, j, str_error(ret)); 81 } 82 bool mute = false; 83 ret = audio_mixer_channel_mute_get( 84 exch, i, j, &mute); 85 if (ret != EOK) { 86 printf("Failed to get channel %u-%u mute" 87 " status: %s.\n", i, j, str_error(ret)); 88 } 70 ret = audio_mixer_get_item_level(exch, i, ¤t); 71 if (ret != EOK) { 72 printf("Failed to get item %u info: %s.\n", 73 i, str_error(ret)); 74 continue; 75 } 89 76 90 printf("\tChannel(%u/%u) %s %s volume: %u/%u%s.\n", 91 i, j, name, chan, level, max, mute ? " (M)":""); 92 free(chan); 93 } 77 printf("Control item %u `%s' : %u/%u.\n", 78 i, name, current, levels - 1); 94 79 free(name); 95 80 96 81 } 97 82 } 98 /*----------------------------------------------------------------------------*/ 83 99 84 static unsigned get_number(const char* str) 100 85 { … … 103 88 return num; 104 89 } 105 /*----------------------------------------------------------------------------*/ 106 static void set_volume(async_exch_t *exch, int argc, char *argv[]) 107 { 108 assert(exch); 109 if (argc != 5 && argc != 6) { 110 printf("%s [device] setvolume item channel value\n", argv[0]); 111 } 112 unsigned params = argc == 6 ? 3 : 2; 113 const unsigned item = get_number(argv[params++]); 114 const unsigned channel = get_number(argv[params++]); 115 const unsigned value = get_number(argv[params]); 116 int ret = audio_mixer_channel_volume_set(exch, item, channel, value); 117 if (ret != EOK) { 118 printf("Failed to set mixer volume: %s.\n", str_error(ret)); 119 return; 120 } 121 printf("Channel %u-%u volume set to %u.\n", item, channel, value); 122 } 123 /*----------------------------------------------------------------------------*/ 124 static void get_volume(async_exch_t *exch, int argc, char *argv[]) 90 91 static void set_level(async_exch_t *exch, int argc, char *argv[]) 125 92 { 126 93 assert(exch); 127 94 if (argc != 4 && argc != 5) { 128 printf("%s [device] getvolume item channel\n", argv[0]); 95 printf("%s [device] setlevel item value\n", argv[0]); 96 return; 129 97 } 130 98 unsigned params = argc == 5 ? 3 : 2; 131 99 const unsigned item = get_number(argv[params++]); 132 const unsigned channel = get_number(argv[params++]); 133 unsigned value = 0, max = 0; 134 135 int ret = audio_mixer_channel_volume_get( 136 exch, item, channel, &value, &max); 100 const unsigned value = get_number(argv[params]); 101 int ret = audio_mixer_set_item_level(exch, item, value); 137 102 if (ret != EOK) { 138 printf("Failed to get mixer volume: %s.\n", str_error(ret));103 printf("Failed to set item level: %s.\n", str_error(ret)); 139 104 return; 140 105 } 141 printf("C hannel %u-%u volume: %u/%u.\n", item, channel, value, max);106 printf("Control item %u new level is %u.\n", item, value); 142 107 } 143 /*----------------------------------------------------------------------------*/ 108 109 static void get_level(async_exch_t *exch, int argc, char *argv[]) 110 { 111 assert(exch); 112 if (argc != 3 && argc != 4) { 113 printf("%s [device] getlevel item \n", argv[0]); 114 return; 115 } 116 unsigned params = argc == 4 ? 3 : 2; 117 const unsigned item = get_number(argv[params++]); 118 unsigned value = 0; 119 120 int ret = audio_mixer_get_item_level(exch, item, &value); 121 if (ret != EOK) { 122 printf("Failed to get item level: %s.\n", str_error(ret)); 123 return; 124 } 125 printf("Control item %u level: %u.\n", item, value); 126 } 127 144 128 int main(int argc, char *argv[]) 145 129 { … … 147 131 void (*command)(async_exch_t *, int, char*[]) = NULL; 148 132 149 if (argc >= 2 && str_cmp(argv[1], "set volume") == 0) {150 command = set_ volume;151 if (argc == 6)133 if (argc >= 2 && str_cmp(argv[1], "setlevel") == 0) { 134 command = set_level; 135 if (argc == 5) 152 136 device = argv[1]; 153 137 } 154 138 155 if (argc >= 2 && str_cmp(argv[1], "get volume") == 0) {156 command = get_ volume;157 if (argc == 5)139 if (argc >= 2 && str_cmp(argv[1], "getlevel") == 0) { 140 command = get_level; 141 if (argc == 4) 158 142 device = argv[1]; 159 143 }
Note:
See TracChangeset
for help on using the changeset viewer.