2 * Common Source Project/ Qt
3 * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
4 * Qt: Menu->Sound Implementations.
5 * History: Jan 14, 2015 : Initial
8 #include "commonclasses.h"
9 #include "mainwidget_base.h"
10 //#include "menuclasses.h"
11 #include "sound_dialog.h"
12 #include <QImageReader>
15 // WIP: Will move to another file
16 const int s_freq_table[8] = {
17 2000, 4000, 8000, 11025, 22050, 44100,
18 #ifdef OVERRIDE_SOUND_FREQ_48000HZ
19 OVERRIDE_SOUND_FREQ_48000HZ,
25 const double s_late_table[5] = {0.05, 0.1, 0.2, 0.3, 0.4};
27 void Object_Menu_Control::on_set_freq(void) {
31 void Object_Menu_Control::on_set_latency(void) {
32 emit sig_latency(s_num);
37 void Ui_MainWindowBase::rise_volume_dialog(void)
39 Ui_SoundDialog *dlg = new Ui_SoundDialog(using_flags, emu, this);
42 QIcon img = QIcon(":/icon_speaker.png");
44 dlg->setWindowIcon(img);
45 this->retranslateVolumeLabels(dlg);
47 n = (float)(((using_flags->get_config_ptr()->general_sound_level + 32768) * 1000) / 65535) / 10.0;
48 s_val.setNum(n, 'f', 1);
49 tmps = QApplication::translate("Ui_SoundDialog", "Set Volume", 0);
50 tmps = tmps + QString::fromUtf8(" (") + s_val + QString::fromUtf8("%)");
51 dlg->setWindowTitle(tmps);
56 void Ui_MainWindowBase::retranslateVolumeLabels(Ui_SoundDialog *)
60 void Ui_MainWindowBase::CreateSoundMenu(void)
62 if(using_flags->is_without_sound()) return;
64 // menuRecord = new QMenu(menuSound);
65 // menuRecord->setObjectName(QString::fromUtf8("menuRecord_Sound"));
67 menuSound->addAction(actionStart_Record);
68 menuSound->addSeparator();
69 menuOutput_Frequency = new QMenu(menuSound);
70 menuOutput_Frequency->setObjectName(QString::fromUtf8("menuOutput_Frequency"));
71 menuSound->addAction(menuOutput_Frequency->menuAction());
72 menuSound->addSeparator();
74 if(using_flags->is_datarec_sound()) {
75 actionSoundCMT = new Action_Control(this, using_flags);
76 actionSoundCMT->setObjectName(QString::fromUtf8("actionSoundCMT"));
77 actionSoundCMT->setCheckable(true);
78 if(using_flags->get_config_ptr()->tape_sound != 0) {
79 actionSoundCMT->setChecked(true);
81 actionSoundCMT->setChecked(false);
83 connect(actionSoundCMT, SIGNAL(toggled(bool)),
84 this, SLOT(set_cmt_sound(bool)));
85 menuSound->addAction(actionSoundCMT);
86 menuSound->addSeparator();
88 for(i = 0; i < 8; i++) {
89 menuOutput_Frequency->addAction(action_Freq[i]);
90 connect(action_Freq[i], SIGNAL(triggered()),
91 action_Freq[i]->binds, SLOT(on_set_freq()));
92 connect(action_Freq[i]->binds, SIGNAL(sig_freq(int)),
93 this, SLOT(set_freq(int)));
95 menuSound_Latency = new QMenu(menuSound);
96 menuSound_Latency->setObjectName(QString::fromUtf8("menuSound_Latency"));
97 menuSound->addAction(menuSound_Latency->menuAction());
98 for(i = 0; i < 5; i++) {
99 menuSound_Latency->addAction(action_Latency[i]);
100 connect(action_Latency[i], SIGNAL(triggered()),
101 action_Latency[i]->binds, SLOT(on_set_latency()));
102 connect(action_Latency[i]->binds, SIGNAL(sig_latency(int)),
103 this, SLOT(set_latency(int)));
105 menuSound->addAction(action_VolumeDialog);
108 void Ui_MainWindowBase::ConfigSoundMenu(void)
110 if(using_flags->is_without_sound()) return;
117 actionGroup_Sound_Freq = new QActionGroup(this);
118 actionGroup_Sound_Freq->setExclusive(true);
120 for(i = 0; i < 8; i++) {
121 action_Freq[i] = new Action_Control(this, using_flags);
122 tmps.setNum(s_freq_table[i]);
123 tmps = QString::fromUtf8("action") + tmps + QString::fromUtf8("Hz");
124 action_Freq[i]->setObjectName(tmps);
125 action_Freq[i]->setCheckable(true);
126 action_Freq[i]->binds->setNumber(i);
127 if(i == using_flags->get_config_ptr()->sound_frequency) {
128 action_Freq[i]->setChecked(true);
129 freq = s_freq_table[i];
131 actionGroup_Sound_Freq->addAction(action_Freq[i]);
133 actionGroup_Sound_Latency = new QActionGroup(this);
134 actionGroup_Sound_Latency->setExclusive(true);
136 for(i = 0; i < 5; i++) {
137 action_Latency[i] = new Action_Control(this, using_flags);
138 dval = s_late_table[i];
139 dval = dval * 1000.0;
140 tmps.setNum((int)dval);
141 tmps = QString::fromUtf8("action") + tmps + QString::fromUtf8("ms");
142 action_Latency[i]->setObjectName(tmps);
143 action_Latency[i]->setCheckable(true);
144 action_Latency[i]->binds->setNumber(i);
145 if(i == using_flags->get_config_ptr()->sound_latency) action_Latency[i]->setChecked(true);
146 actionGroup_Sound_Latency->addAction(action_Latency[i]);
149 actionStart_Record = new Action_Control(this, using_flags);
150 actionStart_Record->setObjectName(QString::fromUtf8("actionStart_Record"));
151 actionStart_Record->setCheckable(true);
152 actionStart_Record->setChecked(false);
153 connect(actionStart_Record, SIGNAL(toggled(bool)), this, SLOT(start_record_sound(bool)));
155 action_VolumeDialog = new Action_Control(this, using_flags);
156 connect(action_VolumeDialog, SIGNAL(triggered()), this, SLOT(rise_volume_dialog()));
157 action_VolumeDialog->setObjectName(QString::fromUtf8("actionVolumedialog"));
160 void Ui_MainWindowBase::do_update_volume(int level)
162 if(using_flags->is_without_sound()) return;
163 if(level <= -32768) {
164 action_VolumeDialog->setIcon(VolumeMutedIcon);
165 } else if(level < -4096) {
166 action_VolumeDialog->setIcon(VolumeLowIcon);
167 } else if(level < 16384) {
168 action_VolumeDialog->setIcon(VolumeMidIcon);
170 action_VolumeDialog->setIcon(VolumeHighIcon);
174 void Ui_MainWindowBase::retranslateSoundMenu(void)
179 if(using_flags->is_without_sound()) return;
181 for(i = 0; i < 8; i++) {
182 tmps.setNum(s_freq_table[i]);
183 tmps = tmps + QApplication::translate("MainWindow", "Hz", 0);
184 action_Freq[i]->setText(tmps);
186 for(i = 0; i < 5; i++) {
187 dval = s_late_table[i];
188 dval = dval * 1000.0;
189 tmps.setNum((int)dval);
190 tmps = tmps + QApplication::translate("MainWindow", "mSec", 0);
191 action_Latency[i]->setText(tmps);
193 actionStart_Record->setIcon(RecordSoundIcon);
194 actionStart_Record->setText(QApplication::translate("MainWindow", "Start Recording Sound", 0));
195 if(using_flags->is_datarec_sound()) {
196 actionSoundCMT->setText(QApplication::translate("MainWindow", "Sound CMT", 0));
198 menuSound->setTitle(QApplication::translate("MainWindow", "Sound", 0));
199 menuOutput_Frequency->setTitle(QApplication::translate("MainWindow", "Output Frequency", 0));
200 menuSound_Latency->setTitle(QApplication::translate("MainWindow", "Sound Latency", 0));
201 action_VolumeDialog->setText(QApplication::translate("MainWindow", "Set Volumes", 0));
203 do_update_volume(using_flags->get_config_ptr()->general_sound_level);