OSDN Git Service

cd00bb0861ed4aec5f0a7ffc637e42b01ba4f772
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / menu_sound.cpp
1 /*
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
6  */
7
8 #include "commonclasses.h"
9 #include "mainwidget_base.h"
10 //#include "menuclasses.h"
11 #include "sound_dialog.h"
12 #include <QImageReader>
13 #include <QImage>
14
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,
20 #else
21                 48000,
22 #endif
23                 96000,
24 };
25 const double s_late_table[5] = {0.05, 0.1, 0.2, 0.3, 0.4};
26
27 void Object_Menu_Control::on_set_freq(void) {
28    emit sig_freq(s_num);
29 }
30
31 void Object_Menu_Control::on_set_latency(void) {
32    emit sig_latency(s_num);
33 }
34
35
36
37 void Ui_MainWindowBase::rise_volume_dialog(void)
38 {
39         Ui_SoundDialog *dlg = new Ui_SoundDialog(using_flags, emu, this);
40         QString tmps, s_val;
41         float n;
42         QIcon  img = QIcon(":/icon_speaker.png");
43         
44         dlg->setWindowIcon(img);
45         this->retranslateVolumeLabels(dlg);
46
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);
52         dlg->show();
53         //dlg->exec();
54 }
55
56 void Ui_MainWindowBase::retranslateVolumeLabels(Ui_SoundDialog *)
57 {
58 }
59
60 void Ui_MainWindowBase::CreateSoundMenu(void)
61 {
62         if(using_flags->is_without_sound()) return;
63         int i;
64         //  menuRecord = new QMenu(menuSound);
65         //  menuRecord->setObjectName(QString::fromUtf8("menuRecord_Sound"));
66   
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();
73         
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);
80                 } else {
81                         actionSoundCMT->setChecked(false);
82                 }
83                 connect(actionSoundCMT, SIGNAL(toggled(bool)),
84                                 this, SLOT(set_cmt_sound(bool)));
85                 menuSound->addAction(actionSoundCMT);
86                 menuSound->addSeparator();
87         }
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)));
94         }
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)));
104         }
105         menuSound->addAction(action_VolumeDialog);
106 }
107
108 void Ui_MainWindowBase::ConfigSoundMenu(void)
109 {
110         if(using_flags->is_without_sound()) return;
111         int i;
112         QString tmps;
113         double dval;
114         int freq = 48000;
115
116
117         actionGroup_Sound_Freq = new QActionGroup(this);
118         actionGroup_Sound_Freq->setExclusive(true);
119         
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];
130                 }
131                 actionGroup_Sound_Freq->addAction(action_Freq[i]);
132         }
133         actionGroup_Sound_Latency = new QActionGroup(this);
134         actionGroup_Sound_Latency->setExclusive(true);
135
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]);
147         }
148
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)));
154
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"));
158 }
159
160 void Ui_MainWindowBase::do_update_volume(int level)
161 {
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);
169         } else {
170                 action_VolumeDialog->setIcon(VolumeHighIcon);
171         }
172 }
173         
174 void Ui_MainWindowBase::retranslateSoundMenu(void)
175 {
176         int i;
177         QString tmps;
178         double dval;
179         if(using_flags->is_without_sound()) return;
180   
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);
185         }
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);
192         }
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));
197         }
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));
202
203         do_update_volume(using_flags->get_config_ptr()->general_sound_level);
204 }