📄 audio_dialog.cpp
字号:
void CreateBitRateMenu()
{
u_int8_t i;
u_int16_t oldBitRate = bitRateValues[bitRateIndex];
u_int32_t samplingRate = samplingRateValues[samplingRateIndex];
// free up old names
for (i = 0; i < bitRateNumber; i++) {
free(bitRateNames[i]);
bitRateNames[i] = NULL;
}
bitRateNumber = 0;
// make current bitrate index invalid, will fixup below
bitRateIndex = 255;
// for all possible bitrates
for (i = 0; i < bitRateAllNumber; i++) {
// MP3 can't use all the possible bit rates
// LAME imposes additional constraints
if (encodingIndex == 0) {
if (samplingRate >= 32000) {
// MPEG-1
if (bitRateAllValues[i] < 40
|| bitRateAllValues[i] == 144) {
continue;
}
if (samplingRate >= 44100 && bitRateAllValues[i] < 56) {
continue;
}
if (samplingRate >= 48000 && bitRateAllValues[i] < 64) {
continue;
}
} else {
// MPEG-2 or MPEG-2.5
if (samplingRate > 16000) {
if (bitRateAllValues[i] < 32) {
continue;
}
}
if (bitRateAllValues[i] > 160) {
continue;
}
}
}
char buf[64];
snprintf(buf, sizeof(buf), "%u",
bitRateAllValues[i]);
bitRateNames[bitRateNumber] = stralloc(buf);
bitRateValues[bitRateNumber] = bitRateAllValues[i];
// preserve user's current choice if we can
if (oldBitRate == bitRateValues[bitRateNumber]) {
bitRateIndex = bitRateNumber;
}
bitRateNumber++;
}
if (bitRateIndex >= bitRateNumber) {
bitRateIndex = bitRateNumber - 1;
}
// (re)create the menu
bit_rate_menu = CreateOptionMenu(
bit_rate_menu,
bitRateNames,
bitRateNumber,
bitRateIndex,
GTK_SIGNAL_FUNC(on_bit_rate_menu_activate));
}
static bool ValidateAndSave(void)
{
// if source has been modified
if (source_modified) {
// validate it
ChangeSource();
// can't validate
if (source_modified) {
return false;
}
}
// copy new values to config
MyConfig->SetStringValue(CONFIG_AUDIO_SOURCE_TYPE,
source_type);
MyConfig->SetStringValue(CONFIG_AUDIO_SOURCE_NAME,
gtk_entry_get_text(GTK_ENTRY(source_entry)));
MyConfig->UpdateFileHistory(
gtk_entry_get_text(GTK_ENTRY(source_entry)));
if (MyConfig->m_audioCapabilities != pAudioCaps) {
delete MyConfig->m_audioCapabilities;
MyConfig->m_audioCapabilities = pAudioCaps;
}
MyConfig->SetStringValue(CONFIG_AUDIO_INPUT_NAME,
inputValues[inputIndex]);
MyConfig->SetIntegerValue(CONFIG_AUDIO_SOURCE_TRACK,
trackValues ? trackValues[trackIndex] : 0);
MyConfig->SetIntegerValue(CONFIG_AUDIO_CHANNELS,
channelValues[channelIndex]);
if (encodingIndex == 1) {
MyConfig->SetStringValue(CONFIG_AUDIO_ENCODING, AUDIO_ENCODING_AAC);
MyConfig->SetStringValue(CONFIG_AUDIO_ENCODER, AUDIO_ENCODER_FAAC);
} else {
MyConfig->SetStringValue(CONFIG_AUDIO_ENCODING, AUDIO_ENCODING_MP3);
MyConfig->SetStringValue(CONFIG_AUDIO_ENCODER, AUDIO_ENCODER_LAME);
}
MyConfig->SetIntegerValue(CONFIG_AUDIO_SAMPLE_RATE,
samplingRateValues[samplingRateIndex]);
MyConfig->SetIntegerValue(CONFIG_AUDIO_BIT_RATE,
bitRateValues[bitRateIndex]);
MyConfig->Update();
DisplayAudioSettings(); // display settings in main window
DisplayStatusSettings();
return true;
}
static void on_ok_button (GtkWidget *widget, gpointer *data)
{
// check and save values
if (!ValidateAndSave()) {
return;
}
on_destroy_dialog(NULL, NULL);
}
static void on_cancel_button (GtkWidget *widget, gpointer *data)
{
on_destroy_dialog(NULL, NULL);
}
void CreateAudioDialog (void)
{
GtkWidget* hbox;
GtkWidget* vbox;
GtkWidget* hbox2;
GtkWidget* label;
GtkWidget* button;
pAudioCaps = MyConfig->m_audioCapabilities;
dialog = gtk_dialog_new();
gtk_signal_connect(GTK_OBJECT(dialog),
"destroy",
GTK_SIGNAL_FUNC(on_destroy_dialog),
&dialog);
gtk_window_set_title(GTK_WINDOW(dialog), "Audio Settings");
hbox = gtk_hbox_new(FALSE, 1);
gtk_widget_show(hbox);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox,
FALSE, FALSE, 5);
vbox = gtk_vbox_new(TRUE, 1);
gtk_widget_show(vbox);
gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 5);
label = gtk_label_new(" Source:");
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
input_label = gtk_label_new(" Input Port:");
gtk_misc_set_alignment(GTK_MISC(input_label), 0.0, 0.5);
gtk_box_pack_start(GTK_BOX(vbox), input_label, FALSE, FALSE, 0);
track_label = gtk_label_new(" Track:");
gtk_misc_set_alignment(GTK_MISC(track_label), 0.0, 0.5);
gtk_box_pack_start(GTK_BOX(vbox), track_label, FALSE, FALSE, 0);
label = gtk_label_new(" Output:");
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
label = gtk_label_new(" Encoding :");
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
label = gtk_label_new(" Channels:");
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
label = gtk_label_new(" Sampling Rate (Hz):");
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
label = gtk_label_new(" Bit Rate (kbps):");
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
vbox = gtk_vbox_new(TRUE, 1);
gtk_widget_show(vbox);
gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 5);
hbox2 = gtk_hbox_new(FALSE, 1);
gtk_widget_show(hbox2);
gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 0);
source_type = MyConfig->GetStringValue(CONFIG_AUDIO_SOURCE_TYPE);
// source entry
free(source_name);
source_name =
stralloc(MyConfig->GetStringValue(CONFIG_AUDIO_SOURCE_NAME));
source_modified = false;
source_combo = CreateFileCombo(source_name);
source_entry = GTK_COMBO(source_combo)->entry;
SetEntryValidator(GTK_OBJECT(source_entry),
GTK_SIGNAL_FUNC(on_source_entry_changed),
GTK_SIGNAL_FUNC(on_source_leave));
source_list = GTK_COMBO(source_combo)->list;
gtk_signal_connect(GTK_OBJECT(source_list), "select_child",
GTK_SIGNAL_FUNC(on_source_list_changed), NULL);
gtk_widget_show(source_combo);
gtk_box_pack_start(GTK_BOX(hbox2), source_combo, TRUE, TRUE, 0);
// browse button
browse_button = gtk_button_new_with_label(" Browse... ");
gtk_signal_connect(GTK_OBJECT(browse_button),
"clicked",
GTK_SIGNAL_FUNC(on_source_browse_button),
NULL);
gtk_widget_show(browse_button);
gtk_box_pack_start(GTK_BOX(hbox2), browse_button, FALSE, FALSE, 5);
// input menu
inputIndex = 0;
for (u_int8_t i = 0; i < sizeof(inputValues) / sizeof(u_int8_t); i++) {
if (!strcasecmp(MyConfig->GetStringValue(CONFIG_AUDIO_INPUT_NAME),
inputValues[i])) {
inputIndex = i;
break;
}
}
input_menu = CreateOptionMenu (NULL,
inputNames,
sizeof(inputNames) / sizeof(char*),
inputIndex,
GTK_SIGNAL_FUNC(on_input_menu_activate));
gtk_box_pack_start(GTK_BOX(vbox), input_menu, TRUE, TRUE, 0);
// track menu
track_menu = NULL;
track_menu = CreateTrackMenu(
track_menu,
'A',
gtk_entry_get_text(GTK_ENTRY(source_entry)),
&trackIndex,
&trackNumber,
&trackValues);
trackIndex = 0;
for (u_int8_t i = 0; i < trackNumber; i++) {
if (MyConfig->GetIntegerValue(CONFIG_AUDIO_SOURCE_TRACK)
== trackValues[i]) {
trackIndex = i;
break;
}
}
gtk_box_pack_start(GTK_BOX(vbox), track_menu, FALSE, FALSE, 0);
// spacer
label = gtk_label_new(" ");
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
if (!strcasecmp(MyConfig->GetStringValue(CONFIG_AUDIO_ENCODING),
AUDIO_ENCODING_AAC)) {
encodingIndex = 1;
} else {
encodingIndex = 0;
}
encoding_menu = CreateOptionMenu (NULL,
encodingNames,
sizeof(encodingNames) / sizeof(char*),
encodingIndex,
GTK_SIGNAL_FUNC(on_encoding_menu_activate));
gtk_box_pack_start(GTK_BOX(vbox), encoding_menu, TRUE, TRUE, 0);
// channel menu
channelIndex = 0;
for (u_int8_t i = 0; i < sizeof(channelValues) / sizeof(u_int8_t); i++) {
if (MyConfig->GetIntegerValue(CONFIG_AUDIO_CHANNELS)
== channelValues[i]) {
channelIndex = i;
break;
}
}
channel_menu = CreateOptionMenu (NULL,
channelNames,
sizeof(channelNames) / sizeof(char*),
channelIndex,
GTK_SIGNAL_FUNC(on_channel_menu_activate));
gtk_box_pack_start(GTK_BOX(vbox), channel_menu, TRUE, TRUE, 0);
sampling_rate_menu = NULL;
CreateSamplingRateMenu(pAudioCaps);
gtk_box_pack_start(GTK_BOX(vbox), sampling_rate_menu, TRUE, TRUE, 0);
// set sampling rate value based on MyConfig
SetSamplingRate(MyConfig->GetIntegerValue(CONFIG_AUDIO_SAMPLE_RATE));
bit_rate_menu = NULL;
CreateBitRateMenu();
gtk_box_pack_start(GTK_BOX(vbox), bit_rate_menu, TRUE, TRUE, 0);
// set bit rate value based on MyConfig
for (u_int8_t i = 0; i < bitRateNumber; i++) {
if (MyConfig->GetIntegerValue(CONFIG_AUDIO_BIT_RATE)
== bitRateValues[i]) {
bitRateIndex = i;
break;
}
}
gtk_option_menu_set_history(
GTK_OPTION_MENU(bit_rate_menu), bitRateIndex);
// Add standard buttons at bottom
button = AddButtonToDialog(dialog,
" OK ",
GTK_SIGNAL_FUNC(on_ok_button));
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
AddButtonToDialog(dialog,
" Cancel ",
GTK_SIGNAL_FUNC(on_cancel_button));
ShowSourceSpecificSettings();
gtk_widget_show(dialog);
}
/* end audio_dialog.cpp */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -