2 * Qt / Tape Menu, Utilities
3 * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
9 #include "menuclasses.h"
10 #include "emu_utils.h"
11 #include "qt_dialogs.h"
13 #include "agar_logger.h"
16 void Object_Menu_Control::start_insert_play_cmt(void) {
18 emit sig_insert_play_cmt(play);
20 void Object_Menu_Control::eject_cmt(void) {
23 void Object_Menu_Control::on_recent_cmt(){
24 emit sig_recent_cmt(s_num);
26 void Object_Menu_Control::do_set_write_protect_cmt(void) {
28 emit sig_set_write_protect_cmt(write_protect);
30 void Object_Menu_Control::do_unset_write_protect_cmt(void) {
31 write_protect = false;
32 emit sig_set_write_protect_cmt(write_protect);
39 void Ui_MainWindow::do_write_protect_cmt(bool flag)
45 int Ui_MainWindow::set_recent_cmt(int num)
49 if((num < 0) || (num >= MAX_HISTORY)) return;
51 path = config.recent_tape_path[num];
52 for(int i = num; i > 0; i--) {
53 strcpy(config.recent_tape_path[i], config.recent_tape_path[i - 1]);
55 strcpy(config.recent_tape_path[0], path.c_str());
57 AGAR_DebugLog(AGAR_LOG_DEBUG, "Tape: Open READ");
58 emu->play_tape(path.c_str()); // Play Readonly, to safety.
60 for(i = 0; i < MAX_HISTORY; i++) {
61 if(action_Recent_List_CMT[i] != NULL) {
62 action_Recent_List_CMT[i]->setText(config.recent_tape_path[i]);
63 //emit action_Recent_List_FD[drive][i]->changed();
69 void Ui_MainWindow::open_cmt_dialog(bool play)
77 #if defined(_PC6001) || defined(_PC6001MK2) || defined(_PC6001MK2SR) || defined(_PC6601) || defined(_PC6601SR)
78 ext = "*.wav *.p6 *.cas";
79 #elif defined(_PC8001SR) || defined(_PC8801MA) || defined(_PC98DO)
80 ext = play ? "*.cas *.cmt *.n80 *.t88" : "*.cas *.cmt";
81 #elif defined(_MZ80A) || defined(_MZ80K) || defined(_MZ1200) || defined(_MZ700) || defined(_MZ800) || defined(_MZ1500)
82 ext = play ? "*.wav *.cas *.mzt *.m12" :"*.wav *.cas";
83 #elif defined(_MZ80B) || defined(_MZ2000) || defined(_MZ2200)
84 ext = play ? "*.wav *.cas *.mzt *.mti *.mtw *.dat" : "*.wav *.cas";
85 #elif defined(_X1) || defined(_X1TWIN) || defined(_X1TURBO) || defined(_X1TURBOZ)
86 ext = play ? "*.wav *.cas *.tap" : "*.wav *.cas";
87 #elif defined(_FM7) || defined(_FM77) || defined(_FM77AV) || defined(_FM77AV40)
89 #elif defined(TAPE_BINARY_ONLY)
94 desc1 = play ? "Data Recorder Tape [Play]" : "Data Recorder Tape [Rec]";
96 dlg.setWindowTitle("Open Tape");
98 dlg.setWindowTitle("Record Tape");
100 desc2 = desc1 + " (" + ext.toLower() + ")";
101 desc1 = desc1 + " (" + ext.toUpper() + ")";
102 if(config.initial_tape_dir != NULL) {
103 dirname = config.initial_tape_dir;
107 dirname = df.currentPath();
108 strncpy(app, dirname.toUtf8().constData(), PATH_MAX);
109 dirname = get_parent_dir(app);
112 filter << desc1 << desc2;
113 dlg.param->setRecMode(play);
114 dlg.setNameFilters(filter);
115 QObject::connect(&dlg, SIGNAL(fileSelected(QString)), dlg.param, SLOT(_open_cmt(QString)));
116 QObject::connect(dlg.param, SIGNAL(do_open_cmt(bool, QString)), this, SLOT(_open_cmt(bool, QString)));
124 void Ui_MainWindow::set_wave_shaper(bool f)
126 config.wave_shaper = f;
128 bool Ui_MainWindow::get_wave_shaper(void)
130 if(config.wave_shaper == 0) return false;
134 void Ui_MainWindow::set_direct_load_from_mzt(bool f)
136 config.direct_load_mzt = f;
138 bool Ui_MainWindow::get_direct_load_mzt(void)
140 if(config.direct_load_mzt == 0) return false;
144 #ifdef USE_TAPE_BUTTON
145 void Ui_MainWindow::OnPushPlayButton(void)
147 if(emu) emu->push_play();
149 void Ui_MainWindow::OnPushStopButton(void)
151 if(emu) emu->push_stop();
156 void Ui_MainWindow::_open_cmt(bool mode, const QString path)
158 char path_shadow[PATH_MAX];
161 play = (mode == false)? 0 : 1;
163 if(path.length() <= 0) return;
164 strncpy(path_shadow, path.toUtf8().constData(), PATH_MAX);
165 UPDATE_HISTORY(path_shadow, config.recent_tape_path);
166 get_parent_dir(path_shadow);
167 strcpy(config.initial_tape_dir, path_shadow);
168 // Copy filename again.
169 strncpy(path_shadow, path.toUtf8().constData(), PATH_MAX);
170 if((play != false) || (write_protect != false)) {
171 AGAR_DebugLog(AGAR_LOG_DEBUG, "Tape: Open READ : filename = %s", path_shadow);
172 emu->play_tape(path_shadow);
174 AGAR_DebugLog(AGAR_LOG_DEBUG, "Tape: Open Write : filename = %s", path_shadow);
175 emu->rec_tape(path_shadow);
180 void Ui_MainWindow::eject_cmt(void)
182 if(emu) emu->close_tape();
185 void Ui_MainWindow::CreateCMTMenu(Ui_MainWindow *p)
187 menuCMT = new QMenu(menubar);
188 menuCMT->setObjectName(QString::fromUtf8("menuCMT", -1));
189 menuWrite_Protection_CMT = new QMenu(menuCMT);
190 menuWrite_Protection_CMT->setObjectName(QString::fromUtf8("menuWrite_Protection_CMT", -1));
191 //CreateCMTPulldownMenu(p);
194 void Ui_MainWindow::CreateCMTPulldownMenu(Ui_MainWindow *p)
197 menuCMT->addAction(actionInsert_CMT);
198 menuCMT->addAction(actionEject_CMT);
199 menuCMT->addSeparator();
200 menuCMT->addAction(actionPlay_Start);
201 menuCMT->addAction(actionPlay_Stop);
203 menuCMT->addSeparator();
204 menuCMT_Recent = new QMenu(menuCMT);
205 menuCMT_Recent->setObjectName(QString::fromUtf8("Recent_CMT", -1));
206 menuCMT->addAction(menuCMT_Recent->menuAction());
207 // menuCMT->addAction(actionRecent_Opened_FD[0]);
210 for(ii = 0; ii < MAX_HISTORY; ii++) {
211 menuCMT_Recent->addAction(action_Recent_List_CMT[ii]);
212 action_Recent_List_CMT[ii]->setVisible(true);
216 menuCMT->addSeparator();
217 menuCMT->addAction(menuWrite_Protection_CMT->menuAction());
218 menuWrite_Protection_CMT->addAction(actionProtection_ON_CMT);
219 menuWrite_Protection_CMT->addAction(actionProtection_OFF_CMT);
223 void Ui_MainWindow::ConfigCMTMenuSub(Ui_MainWindow *p)
226 actionInsert_CMT = new Action_Control(p);
227 actionInsert_CMT->setObjectName(QString::fromUtf8("actionInsert_CMT"));
228 actionInsert_CMT->binds->setPlay(true);
229 actionInsert_CMT->binds->setNumber(0);
231 actionEject_CMT = new Action_Control(p);
232 actionEject_CMT->setObjectName(QString::fromUtf8("actionEject_CMT"));
233 actionEject_CMT->binds->setPlay(true);
235 actionPlay_Start = new Action_Control(p);
236 actionPlay_Start->setObjectName(QString::fromUtf8("actionPlay_Start"));
237 actionPlay_Start->binds->setPlay(true);
239 actionPlay_Stop = new Action_Control(p);
240 actionPlay_Stop->setObjectName(QString::fromUtf8("actionPlay_Stop"));
241 actionPlay_Stop->binds->setPlay(true);
243 actionRecording = new Action_Control(p);
244 actionRecording->setObjectName(QString::fromUtf8("actionRecording"));
245 actionRecording->binds->setPlay(false);
246 actionRecording->binds->setNumber(0);
248 actionGroup_Opened_CMT = new QActionGroup(p);
249 actionRecent_Opened_CMT = new Action_Control(p);
250 actionRecent_Opened_CMT->setObjectName(QString::fromUtf8("actionRecent_Opened_CMT"));
251 actionRecent_Opened_CMT->binds->setPlay(true);
255 actionGroup_Opened_CMT = new QActionGroup(p);
256 actionGroup_Opened_CMT->setExclusive(true);
258 actionRecent_Opened_CMT = new Action_Control(p);
259 actionRecent_Opened_CMT->setObjectName(QString::fromUtf8("actionSelect_Recent_CMT"));
260 actionRecent_Opened_CMT->binds->setPlay(true); // For safety
261 for(ii = 0; ii < MAX_HISTORY; ii++) {
262 action_Recent_List_CMT[ii] = new Action_Control(p);
263 action_Recent_List_CMT[ii]->binds->setPlay(true);
264 action_Recent_List_CMT[ii]->binds->setNumber(ii);
265 action_Recent_List_CMT[ii]->setText(QString::fromUtf8(config.recent_tape_path[ii]));
266 actionGroup_Opened_CMT->addAction(action_Recent_List_CMT[ii]);
267 connect(action_Recent_List_CMT[ii], SIGNAL(triggered()),
268 action_Recent_List_CMT[ii]->binds, SLOT(on_recent_cmt()));
269 connect(action_Recent_List_CMT[ii]->binds, SIGNAL(sig_recent_cmt(int)),
270 this, SLOT(set_recent_cmt(int)));
276 actionProtection_ON_CMT = new Action_Control(p);
277 actionProtection_ON_CMT->setObjectName(QString::fromUtf8("actionProtection_ON_CMT"));
278 actionProtection_ON_CMT->setCheckable(true);
279 actionProtection_ON_CMT->setChecked(true);
280 actionProtection_OFF_CMT = new Action_Control(p);
281 actionProtection_OFF_CMT->setObjectName(QString::fromUtf8("actionProtection_OFF_CMT"));
282 actionProtection_OFF_CMT->setCheckable(true);
283 actionProtection_OFF_CMT->setChecked(false);
284 connect(actionProtection_OFF_CMT, SIGNAL(triggered()), actionProtection_OFF_CMT->binds, SLOT(do_unset_write_protect_cmt()));
285 connect(actionProtection_OFF_CMT->binds, SIGNAL(sig_set_write_protect_cmt(bool)), this, SLOT(do_write_protect_cmt(bool)));
287 connect(actionProtection_ON_CMT, SIGNAL(triggered()), actionProtection_ON_CMT->binds, SLOT(do_set_write_protect_cmt()));
288 connect(actionProtection_ON_CMT->binds, SIGNAL(sig_set_write_protect_cmt(bool)), this, SLOT(do_write_protect_cmt(bool)));
290 actionGroup_Protect_CMT = new QActionGroup(p);
291 //actionGroup_Protect_CMT->setExclusive(true);
292 actionGroup_Protect_CMT->addAction(actionProtection_ON_CMT);
293 actionGroup_Protect_CMT->addAction(actionProtection_OFF_CMT);
294 actionProtection_ON_CMT->setActionGroup(actionGroup_Protect_CMT);
295 actionProtection_OFF_CMT->setActionGroup(actionGroup_Protect_CMT);
299 connect(actionRecording, SIGNAL(triggered()), actionRecording->binds, SLOT(start_insert_play_cmt()));
300 connect(actionRecording->binds, SIGNAL(sig_insert_play_cmt(bool)), this, SLOT(open_cmt_dialog(bool)));
301 connect(actionInsert_CMT, SIGNAL(triggered()), actionInsert_CMT->binds, SLOT(start_insert_play_cmt()));
302 connect(actionInsert_CMT->binds, SIGNAL(sig_insert_play_cmt(bool)), this, SLOT(open_cmt_dialog(bool)));
303 connect(actionEject_CMT, SIGNAL(triggered()), actionEject_CMT->binds, SLOT(eject_cmt()));
309 void Ui_MainWindow::retranslateCMTMenu(Ui_MainWindow *p)
312 actionInsert_CMT->setText(QApplication::translate("MainWindow", "Insert", 0, QApplication::UnicodeUTF8));
313 actionEject_CMT->setText(QApplication::translate("MainWindow", "Eject", 0, QApplication::UnicodeUTF8));
315 menuCMT_Recent->setTitle(QApplication::translate("MainWindow", "Recent Opened", 0, QApplication::UnicodeUTF8));
317 actionProtection_ON_CMT->setText(QApplication::translate("MainWindow", "Protection ON", 0, QApplication::UnicodeUTF8));
318 actionProtection_OFF_CMT->setText(QApplication::translate("MainWindow", "Protection OFF", 0, QApplication::UnicodeUTF8));
320 menuCMT->setTitle(QApplication::translate("MainWindow", "Casette tape" , 0, QApplication::UnicodeUTF8));
321 menuWrite_Protection_CMT->setTitle(QApplication::translate("MainWindow", "Write Protection", 0, QApplication::UnicodeUTF8));
327 void Ui_MainWindow::ConfigCMTMenu(Ui_MainWindow *p)
330 #if defined(USE_TAPE)
331 write_protect = true;