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 <QImageReader>
11 #include <QActionGroup>
15 #include "commonclasses.h"
16 #include "mainwidget_base.h"
17 //#include "menuclasses.h"
18 #include "sound_dialog.h"
19 #include "menu_flags.h"
22 // WIP: Will move to another file
23 const double s_late_table[5] = {0.05, 0.1, 0.2, 0.3, 0.4};
25 void Ui_MainWindowBase::do_update_sound_output_list(void)
27 if((p_config == nullptr) || (using_flags == nullptr)) return;
29 QString matched_devname = QString::fromUtf8("Default");
30 do_set_host_sound_name(0, QString::fromUtf8("Default"));
32 if(action_HostSoundDevice[0] != nullptr) {
33 action_HostSoundDevice[0]->setChecked(true);
35 QString _setname = QString::fromLocal8Bit(p_config->sound_device_name);
36 _setname.truncate(1023);
37 for(int i = 1; i < 16; i++) {
38 if(action_HostSoundDevice[i] != nullptr) {
39 action_HostSoundDevice[i]->setChecked(false);
41 const _TCHAR* sp = using_flags->get_sound_device_name(i - 1);
45 sname = QString::fromUtf8(sp);
49 if(sname == _setname) {
51 matched_devname = sname;
53 do_set_host_sound_name(i, sname);
56 if(action_HostSoundDevice[_match] != nullptr) {
57 action_HostSoundDevice[_match]->setChecked(true);
60 if(action_HostSoundDevice[0] != nullptr) {
61 action_HostSoundDevice[0]->setChecked(true);
64 emit sig_osd_sound_output_device(matched_devname);
67 void Ui_MainWindowBase::do_set_host_sound_output_device(void)
69 QAction *cp = qobject_cast<QAction*>(QObject::sender());
70 if(cp == nullptr) return;
71 QString _name = cp->data().value<QString>();
73 if(p_config != NULL) {
74 QString _old = QString::fromLocal8Bit(p_config->sound_device_name, 1023);
76 if((_old != _name) && !(_name.isEmpty())) {
77 my_tcscpy_s(p_config->sound_device_name, 1023, _name.toLocal8Bit().constData());
78 emit sig_osd_sound_output_device(_name);
81 emit sig_emu_update_config();
84 void Ui_MainWindowBase::do_set_host_sound_name(int num, QString s)
90 if(action_HostSoundDevice[num] != NULL) {
91 action_HostSoundDevice[num]->setVisible(false);
92 QVariant v = QVariant(QString::fromUtf8(""));
93 action_HostSoundDevice[num]->setData(v);
96 if(action_HostSoundDevice[num] != NULL) {
97 action_HostSoundDevice[num]->setVisible(true);
98 action_HostSoundDevice[num]->setText(s);
99 QVariant v = QVariant(s);
100 action_HostSoundDevice[num]->setData(v);
105 void Ui_MainWindowBase::do_set_sound_strict_rendering(bool f)
107 if(using_flags != NULL) {
108 p_config->sound_strict_rendering = f;
112 void Ui_MainWindowBase::do_set_sound_tape_signal(bool f)
114 if(using_flags != NULL) {
115 p_config->sound_tape_signal = f;
119 void Ui_MainWindowBase::do_set_sound_tape_voice(bool f)
121 if(using_flags != NULL) {
122 p_config->sound_tape_voice = f;
127 void Ui_MainWindowBase::rise_volume_dialog(void)
129 Ui_SoundDialog *dlg = new Ui_SoundDialog(using_flags, this);
132 QIcon img = QIcon(":/icon_speaker.png");
134 dlg->setWindowIcon(img);
135 this->retranslateVolumeLabels(dlg);
137 n = (float)(((p_config->general_sound_level + 32768) * 1000) / 65535) / 10.0;
138 s_val.setNum(n, 'f', 1);
139 tmps = QApplication::translate("Ui_SoundDialog", "Set Volume", 0);
140 tmps = tmps + QString::fromUtf8(" (") + s_val + QString::fromUtf8("%)");
141 dlg->setWindowTitle(tmps);
146 void Ui_MainWindowBase::retranslateVolumeLabels(Ui_SoundDialog *)
150 void Ui_MainWindowBase::CreateSoundMenu(void)
152 if(using_flags->is_without_sound()) return;
154 // menuRecord = new QMenu(menuSound);
155 // menuRecord->setObjectName(QString::fromUtf8("menuRecord_Sound"));
157 menuSound->addAction(actionStart_Record);
158 menuSound->addSeparator();
159 SET_ACTION_CHECKABLE_SINGLE_CONNECT(menuSound, actionSoundStrictRendering,
160 "actionSoundStrictRendering", p_config->sound_strict_rendering,
161 SIGNAL(toggled(bool)), SLOT(do_set_sound_strict_rendering(bool)));
162 SET_ACTION_CHECKABLE_SINGLE_CONNECT(menuSound, actionSoundTapeSignal,
163 "actionSoundTapeSignal", p_config->sound_tape_signal,
164 SIGNAL(toggled(bool)), SLOT(do_set_sound_tape_signal(bool)));
165 SET_ACTION_CHECKABLE_SINGLE_CONNECT(menuSound, actionSoundTapeVoice,
166 "actionSoundTapeVoice", p_config->sound_tape_voice,
167 SIGNAL(toggled(bool)), SLOT(do_set_sound_tape_voice(bool)));
169 //actionSoundStrictRendering = new Action_Control(this, using_flags);
170 //actionSoundStrictRendering->setObjectName(QString::fromUtf8("actionSoundStrictRendering"));
171 //actionSoundStrictRendering->setCheckable(true);
172 //if(p_config->sound_strict_rendering) actionSoundStrictRendering->setChecked(true);
173 //connect(actionSoundStrictRendering, SIGNAL(toggled(bool)),
174 // this, SLOT(do_set_sound_strict_rendering(bool)));
175 //menuSound->addAction(actionSoundStrictRendering);
177 menuSound_HostDevices = new QMenu(menuSound);
178 menuSound_HostDevices->setObjectName(QString::fromUtf8("menuSound_HostDevices"));
179 menuSound->addAction(menuSound_HostDevices->menuAction());
180 for(i = 0; i < 16; i++) {
181 if(action_HostSoundDevice[i] != NULL) {
182 menuSound_HostDevices->addAction(action_HostSoundDevice[i]);
183 connect(action_HostSoundDevice[i], SIGNAL(triggered()),
184 this, SLOT(do_set_host_sound_output_device()));
188 menuSound->addSeparator();
190 menuOutput_Frequency = new QMenu(menuSound);
191 menuOutput_Frequency->setObjectName(QString::fromUtf8("menuOutput_Frequency"));
192 menuSound->addAction(menuOutput_Frequency->menuAction());
193 for(i = 0; i < 8; i++) {
194 menuOutput_Frequency->addAction(action_Freq[i]);
195 connect(action_Freq[i], SIGNAL(triggered()),
196 this, SLOT(do_set_freq()));
198 menuSound_Latency = new QMenu(menuSound);
199 menuSound_Latency->setObjectName(QString::fromUtf8("menuSound_Latency"));
200 menuSound->addAction(menuSound_Latency->menuAction());
201 for(i = 0; i < 5; i++) {
202 menuSound_Latency->addAction(action_Latency[i]);
203 connect(action_Latency[i], SIGNAL(triggered()),
204 this, SLOT(do_set_latency()));
207 menuSound->addSeparator();
208 if(using_flags->is_use_sound_files_fdd()) {
209 SET_ACTION_SINGLE(action_SoundFilesFDD, true, true, (p_config->sound_noise_fdd != 0));
211 if(using_flags->is_use_sound_files_relay()) {
212 SET_ACTION_SINGLE(action_SoundFilesRelay, true, true, (p_config->sound_noise_cmt != 0));
214 if(using_flags->is_use_sound_files_fdd() || using_flags->is_use_sound_files_relay()) {
215 if(using_flags->is_use_sound_files_fdd()) menuSound->addAction(action_SoundFilesFDD);
216 if(using_flags->is_use_sound_files_relay()) menuSound->addAction(action_SoundFilesRelay);
217 menuSound->addSeparator();
219 menuSound->addAction(action_VolumeDialog);
222 void Ui_MainWindowBase::ConfigSoundMenu(void)
224 if(using_flags->is_without_sound()) return;
230 actionGroup_Sound_HostDevices = new QActionGroup(this);
231 for(i = 0; i < 16; i++) {
232 action_HostSoundDevice[i] = new Action_Control(this, using_flags);
234 tmps = QString::fromUtf8("action_HostSoundDevice") + tmps;
235 action_HostSoundDevice[i]->setObjectName(tmps);
236 action_HostSoundDevice[i]->setCheckable(true);
237 QVariant v = QVariant(QString::fromUtf8(""));
238 action_HostSoundDevice[i]->setData(v);
239 actionGroup_Sound_HostDevices->addAction(action_HostSoundDevice[i]);
242 actionGroup_Sound_Freq = new QActionGroup(this);
243 actionGroup_Sound_Freq->setExclusive(true);
244 for(i = 0; i < 8; i++) {
245 action_Freq[i] = new Action_Control(this, using_flags);
246 int _freq = using_flags->get_s_freq_table(i);
248 tmps = QString::fromUtf8("action") + tmps + QString::fromUtf8("Hz");
249 action_Freq[i]->setObjectName(tmps);
250 action_Freq[i]->setCheckable(true);
251 action_Freq[i]->setData(QVariant(i));
252 if(i == p_config->sound_frequency) {
253 action_Freq[i]->setChecked(true);
254 //freq = using_flags->get_s_freq_table(i);
256 actionGroup_Sound_Freq->addAction(action_Freq[i]);
258 actionGroup_Sound_Latency = new QActionGroup(this);
259 actionGroup_Sound_Latency->setExclusive(true);
261 for(i = 0; i < 5; i++) {
262 action_Latency[i] = new Action_Control(this, using_flags);
263 dval = s_late_table[i];
264 dval = dval * 1000.0;
266 tmps = QString::fromUtf8("action") + tmps + QString::fromUtf8("ms");
267 action_Latency[i]->setObjectName(tmps);
268 action_Latency[i]->setCheckable(true);
269 action_Latency[i]->setData(QVariant(i));
270 if(i == p_config->sound_latency) action_Latency[i]->setChecked(true);
271 actionGroup_Sound_Latency->addAction(action_Latency[i]);
274 SET_ACTION_SINGLE(actionStart_Record, true, true, false);
275 //actionStart_Record = new Action_Control(this, using_flags);
276 //actionStart_Record->setObjectName(QString::fromUtf8("actionStart_Record"));
277 //actionStart_Record->setCheckable(true);
278 //actionStart_Record->setChecked(false);
279 connect(actionStart_Record, SIGNAL(toggled(bool)), this, SLOT(start_record_sound(bool)));
281 action_VolumeDialog = new Action_Control(this, using_flags);
282 connect(action_VolumeDialog, SIGNAL(triggered()), this, SLOT(rise_volume_dialog()));
283 action_VolumeDialog->setObjectName(QString::fromUtf8("actionVolumedialog"));
286 void Ui_MainWindowBase::do_update_volume(int level)
288 if(using_flags->is_without_sound()) return;
289 if(level <= INT16_MIN) {
290 action_VolumeDialog->setIcon(VolumeMutedIcon);
291 } else if(level < -4096) {
292 action_VolumeDialog->setIcon(VolumeLowIcon);
293 } else if(level < 16384) {
294 action_VolumeDialog->setIcon(VolumeMidIcon);
296 action_VolumeDialog->setIcon(VolumeHighIcon);
298 emit sig_update_master_volume(level);
301 void Ui_MainWindowBase::retranslateSoundMenu(void)
306 if(using_flags->is_without_sound()) return;
308 for(i = 0; i < 8; i++) {
309 tmps.setNum(using_flags->get_s_freq_table(i));
310 tmps = tmps + QApplication::translate("MenuSound", "Hz", 0);
311 action_Freq[i]->setText(tmps);
313 for(i = 0; i < 5; i++) {
314 dval = s_late_table[i];
315 dval = dval * 1000.0;
316 tmps.setNum((int)dval);
317 tmps = tmps + QApplication::translate("MenuSound", "mSec", 0);
318 action_Latency[i]->setText(tmps);
320 actionStart_Record->setIcon(RecordSoundIcon);
321 actionStart_Record->setText(QApplication::translate("MenuSound", "Start Recording Sound", 0));
322 actionStart_Record->setToolTip(QApplication::translate("MenuSound", "Record sound as WAV file.", 0));
324 actionSoundStrictRendering->setText(QApplication::translate("MenuSound", "Strict Rendering", 0));
325 actionSoundStrictRendering->setToolTip(QApplication::translate("MenuSound", "Rendering per a sample.Select to slower, but accurate rendering sound.", 0));
326 actionSoundTapeSignal->setText(QApplication::translate("MenuSound", "Play CMT Signal", 0));
327 actionSoundTapeSignal->setToolTip(QApplication::translate("MenuSound", "Play Signal from CMTs.", 0));
329 actionSoundTapeVoice->setText(QApplication::translate("MenuSound", "Play CMT Voice", 0));
330 actionSoundTapeVoice->setToolTip(QApplication::translate("MenuSound", "Play Audio/Voice from CMTs.", 0));
332 if(using_flags->is_tape_binary_only()) {
333 actionSoundTapeSignal->setEnabled(false);
334 actionSoundTapeVoice->setEnabled(false);
335 actionSoundTapeSignal->setVisible(false);
336 actionSoundTapeVoice->setVisible(false);
339 menuSound_HostDevices->setTitle(QApplication::translate("MenuSound", "Output to:", 0));
340 menuSound_HostDevices->setToolTip(QApplication::translate("MenuSound", "Select sound device to output.\nThis effects after re-start this emulator.", 0));
342 menuSound->setTitle(QApplication::translate("MenuSound", "Sound", 0));
343 menuOutput_Frequency->setTitle(QApplication::translate("MenuSound", "Output Frequency", 0));
344 menuSound_Latency->setTitle(QApplication::translate("MenuSound", "Sound Latency", 0));
346 action_VolumeDialog->setText(QApplication::translate("MenuSound", "Set Volumes", 0));
347 action_VolumeDialog->setToolTip(QApplication::translate("MenuSound", "Open a VOLUME dialog.", 0));
348 if(using_flags->is_use_sound_files_fdd()) {
349 action_SoundFilesFDD->setText(QApplication::translate("MenuSound", "Sound FDD Seek", 0));
350 action_SoundFilesFDD->setToolTip(QApplication::translate("MenuSound", "Enable FDD HEAD seeking sound.\nNeeds sound file.\nSee HELP->READMEs->Bios and Key assigns", 0));
352 if(using_flags->is_use_sound_files_relay()) {
353 action_SoundFilesRelay->setText(QApplication::translate("MenuSound", "Sound CMT Relay and Buttons", 0));
354 action_SoundFilesRelay->setToolTip(QApplication::translate("MenuSound", "Enable CMT relay's sound and buttons's sounds.\nNeeds sound file.\nSee HELP->READMEs->Bios and Key assigns", 0));
355 if(using_flags->is_tape_binary_only()) action_SoundFilesRelay->setEnabled(false);
358 menuSound->setToolTipsVisible(true);
359 do_update_volume(p_config->general_sound_level);