3
#include "kguitar_part.h"
12
#include "melodyeditor.h"
13
#include "trackdrag.h"
16
#include "convertkg.h"
17
#include "convertascii.h"
18
#include "convertxml.h"
19
#include "convertmidi.h"
20
#include "converttse3.h"
21
#include "converttex.h"
22
#include "convertgtp.h"
23
#include "convertgp3.h"
25
#include "optionsexportascii.h"
26
#include "optionsexportmusixtex.h"
29
#include <kparts/genericfactory.h>
35
#include <kstdaction.h>
37
#include <kfiledialog.h>
39
#include <kmessagebox.h>
41
#include <kkeydialog.h>
49
#include <qstatusbar.h>
50
#include <qclipboard.h>
52
#include <qbuttongroup.h>
53
#include <qradiobutton.h>
54
#include <qfileinfo.h>
56
typedef KParts::GenericFactory<KGuitarPart> KGuitarPartFactory;
57
K_EXPORT_COMPONENT_FACTORY(libkguitarpart, KGuitarPartFactory)
59
// Global variables - real declarations
61
QString drum_abbr[128];
63
KGuitarPart::KGuitarPart(QWidget *parentWidget,
64
const char * /*widgetName*/, QObject *parent, const char *name,
65
const QStringList & /*args*/)
66
: KParts::ReadWritePart(parent, name)
68
Settings::config = KGuitarPartFactory::instance()->config();
70
cmdHist = new KCommandHistory();
72
setInstance(KGuitarPartFactory::instance());
75
sv = new SongView(this, cmdHist, parentWidget);
77
// notify the part that this is our internal widget
83
// SET UP RESPONSES FOR VARIOUS TRACK CHANGES
85
connect(sv->tv, SIGNAL(trackChanged(TabTrack *)), SLOT(updateToolbars(TabTrack *)));
86
connect(QApplication::clipboard(), SIGNAL(dataChanged()), SLOT(clipboardDataChanged()));
87
connect(sv->tv, SIGNAL(barChanged()), SLOT(updateStatusBar()));
89
setXMLFile("kguitar_part.rc");
100
KGuitarPart::~KGuitarPart()
106
void KGuitarPart::setReadWrite(bool rw)
108
sv->setReadOnly(!rw);
110
connect(sv, SIGNAL(songChanged()), this, SLOT(setModified()));
112
disconnect(sv, SIGNAL(songChanged()), this, SLOT(setModified()));
115
ReadWritePart::setReadWrite(rw);
118
void KGuitarPart::setModified(bool modified)
120
// enable or disable Save action based on modified
121
KAction *save = actionCollection()->action(KStdAction::stdName(KStdAction::Save));
125
save->setEnabled(modified);
127
// in any event, we want our parent to do it's thing
128
ReadWritePart::setModified(modified);
131
KAboutData *KGuitarPart::createAboutData()
133
KAboutData *aboutData = new KAboutData("kguitar", I18N_NOOP("KGuitarPart"), VERSION);
134
aboutData->addAuthor("KGuitar development team", 0, 0);
138
// Reimplemented method from KParts to open file m_file
139
bool KGuitarPart::openFile()
141
QFileInfo fi(m_file);
144
KMessageBox::sorry(0, i18n("No file specified, please select a file."));
147
if (!fi.isReadable()) {
148
KMessageBox::sorry(0, i18n("You have no permission to read this file."));
152
bool success = FALSE;
154
QString ext = fi.extension();
157
ConvertBase *converter = NULL;
159
if (ext == "kg") converter = new ConvertKg(sv->song());
160
if (ext == "tab") converter = new ConvertAscii(sv->song());
162
if (ext == "mid") converter = new ConvertMidi(sv->song());
164
if (ext == "gp4") converter = new ConvertGtp(sv->song());
165
if (ext == "gp3") converter = new ConvertGp3(sv->song());
166
if (ext == "xml") converter = new ConvertXml(sv->song());
168
if (converter) success = converter->load(m_file);
174
setWinCaption(i18n("Unnamed"));
175
KMessageBox::sorry(0, i18n("Can't load or import song!"
176
"It may be a damaged/wrong file format or, "
177
"if you're trying experimental importers "
178
"it may be a flaw with the import code."));
184
bool KGuitarPart::exportOptionsDialog(QString ext)
186
// Skip dialog if user set appropriate option
187
if (!Settings::config->readBoolEntry("AlwaysShow", TRUE))
190
KDialogBase opDialog(0, 0, TRUE, i18n("Additional Export Options"),
191
KDialogBase::Help|KDialogBase::Default|
192
KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok);
194
QVBox *box = opDialog.makeVBoxMainWidget();
199
op = new OptionsExportAscii(Settings::config, (QFrame *) box);
200
} else if (ext == "tex") {
201
op = new OptionsExportMusixtex(Settings::config, (QFrame *) box);
203
kdWarning() << "Weird exportOptionsDialog() call! Wrong extension " << ext << endl;
207
connect(&opDialog, SIGNAL(defaultClicked()), op, SLOT(defaultBtnClicked()));
208
connect(&opDialog, SIGNAL(okClicked()), op, SLOT(applyBtnClicked()));
210
bool res = (opDialog.exec() == QDialog::Accepted);
215
// Reimplemented method from KParts to current song to file m_file
216
bool KGuitarPart::saveFile()
218
// if we aren't read-write, return immediately
219
if (isReadWrite() == false)
222
// GREYFIX: some sort of dirty hack - workaround the KDE default
223
// save, not saveAs without file name
224
if (m_file.isEmpty()) {
229
QFileInfo *fi = new QFileInfo(m_file);
230
QString ext = fi->extension().lower();
232
bool success = FALSE;
235
sv->tv->arrangeBars(); // GREYFIX !
236
ConvertKg converter(sv->song());
237
success = converter.save(m_file);
240
Settings::config->setGroup("ASCII");
241
if (exportOptionsDialog(ext)) {
242
ConvertAscii converter(sv->song());
243
success = converter.save(m_file);
250
ConvertMidi converter(sv->song());
251
success = converter.save(m_file);
254
ConvertTse3 converter(sv->song());
255
success = converter.save(m_file);
259
ConvertGtp converter(sv->song());
260
success = converter.save(m_file);
263
ConvertGp3 converter(sv->song());
264
success = converter.save(m_file);
267
if (exportOptionsDialog(ext)) {
268
ConvertTex converter(sv->song());
269
success = converter.save(m_file);
275
ConvertXml converter(sv->song());
276
success = converter.save(m_file);
280
setWinCaption(m_file);
283
KMessageBox::sorry(0, i18n("Can't save song in %1 format").arg(ext));
289
void KGuitarPart::fileSaveAs()
292
"*.kg|" + i18n("KGuitar files") + " (*.kg)\n"
293
"*.tab|" + i18n("ASCII files") + " (*.tab)\n"
294
"*.mid|" + i18n("MIDI files") + " (*.mid)\n"
295
"*.tse3|" + i18n("TSE3MDL files") + " (*.tse3)\n"
296
"*.gp4|" + i18n("Guitar Pro 4 files") + " (*.gp4)\n"
297
"*.gp3|" + i18n("Guitar Pro 3 files") + " (*.gp3)\n"
298
"*.xml|" + i18n("MusicXML files") + " (*.xml)\n"
299
"*.tex|" + i18n("MusiXTeX") + " (*.tex)\n"
300
"*|" + i18n("All files");
301
QString file_name = KFileDialog::getSaveFileName(QString::null, filter);
303
if (file_name.isEmpty() == false)
307
// Updates possibility of actions, depending on freshly selected
308
// track. For drum track, lots of actions are unavailable.
309
void KGuitarPart::updateToolbars(TabTrack *)
311
switch (sv->tv->trk()->trackMode()) {
312
case TabTrack::DrumTab:
313
insChordAct->setEnabled(FALSE);
314
natHarmAct->setEnabled(FALSE);
315
artHarmAct->setEnabled(FALSE);
318
insChordAct->setEnabled(TRUE);
319
natHarmAct->setEnabled(TRUE);
320
artHarmAct->setEnabled(TRUE);
324
void KGuitarPart::filePrint()
326
// LVIFIX: enable status message
327
// slotStatusMsg(i18n("Printing..."));
329
KPrinter printer(true, QPrinter::HighResolution);
333
// slotStatusMsg(i18n("Ready."));
336
void KGuitarPart::options()
342
KGuitarPartFactory::instance()->config());
344
sv->me->drawBackground();
347
void KGuitarPart::readOptions()
349
KConfig *config = KGuitarPartFactory::instance()->config();
351
// config->setGroup("MusiXTeX");
352
// globalTabSize = config->readNumEntry("TabSize", 2);
353
// globalShowBarNumb = config->readBoolEntry("ShowBarNumb", TRUE);
354
// globalShowStr = config->readBoolEntry("ShowStr", TRUE);
355
// globalShowPageNumb = config->readBoolEntry("ShowPageNumb", TRUE);
356
// globalTexExpMode = config->readNumEntry("TexExpMode", 0);
358
viewMelodyEditorAct->setChecked(config->readBoolEntry("Visible", TRUE));
360
// viewScoreAct->setChecked(TRUE); // LVIFIX: read value from config, enable only if feta fonts found
361
viewScoreAct->setChecked(FALSE); // LVIFIX: enable before commit
365
void KGuitarPart::saveOptions()
367
Settings::config->setGroup("MelodyEditor");
368
Settings::config->writeEntry("Visible", viewMelodyEditorAct->isChecked());
369
Settings::config->sync();
372
void KGuitarPart::readMidiNames()
374
drum_abbr[35] = QString("BD1");
375
drum_abbr[36] = QString("BD2");
376
drum_abbr[38] = QString("SD1");
377
drum_abbr[40] = QString("SD2");
379
drum_abbr[39] = QString("HCL"); // Hand clap
381
drum_abbr[42] = QString("CHH");
382
drum_abbr[44] = QString("PHH");
383
drum_abbr[46] = QString("OHH");
385
drum_abbr[49] = QString("CR1"); // Crash cymbal
386
drum_abbr[57] = QString("CR2");
388
drum_abbr[51] = QString("RI1"); // Ride cymbal
389
drum_abbr[59] = QString("RI2");
391
drum_abbr[54] = QString("TBR"); // Tamborine
392
drum_abbr[55] = QString("SPL"); // Splash cymbal
394
drum_abbr[41] = QString("TL2");
395
drum_abbr[43] = QString("TL1");
396
drum_abbr[45] = QString("TM2");
397
drum_abbr[47] = QString("TM1");
398
drum_abbr[48] = QString("TH2");
399
drum_abbr[50] = QString("TH1");
402
void KGuitarPart::setWinCaption(const QString& caption)
404
emit setWindowCaption(caption);
407
//-------------------------------------------------------------------
409
// KGuitarBrowserExtension::KGuitarBrowserExtension(KGuitarPart *parent)
410
// : KParts::BrowserExtension(parent, "KGuitarBrowserExtension")
414
// void KGuitarBrowserExtension::print()
416
// ((KGuitarPart *)parent())->filePrint();
419
void KGuitarPart::viewMelodyEditor()
421
if (viewMelodyEditorAct->isChecked())
427
void KGuitarPart::viewScore()
429
if (viewScoreAct->isChecked() /* && sv->sp->fFeta LVIFIX: enable after drawing code merge */)
430
sv->tv->viewScore(true);
432
sv->tv->viewScore(false);
435
void KGuitarPart::setupActions()
437
// SET UP STANDARD ACTIONS
438
KStdAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
439
KStdAction::save(this, SLOT(save()), actionCollection());
441
(void) KStdAction::print(this, SLOT(filePrint()), actionCollection());
442
(void) KStdAction::preferences(this, SLOT(options()), actionCollection());
444
(void) new KAction(i18n("P&roperties..."), 0, sv, SLOT(songProperties()),
445
actionCollection(), "song_properties");
448
(void) KStdAction::undo(cmdHist, SLOT(undo()), actionCollection());
449
(void) KStdAction::redo(cmdHist, SLOT(redo()), actionCollection());
450
(void) KStdAction::cut(sv, SLOT(slotCut()), actionCollection());
451
(void) KStdAction::copy(sv, SLOT(slotCopy()), actionCollection());
452
(void) KStdAction::paste(sv, SLOT(slotPaste()), actionCollection());
453
(void) KStdAction::selectAll(sv, SLOT(slotSelectAll()), actionCollection());
456
(void) KStdAction::zoomIn(sv->tv, SLOT(zoomIn()), actionCollection());
457
(void) KStdAction::zoomOut(sv->tv, SLOT(zoomOut()), actionCollection());
458
(void) KStdAction::zoom(sv->tv, SLOT(zoomLevelDialog()), actionCollection());
459
viewMelodyEditorAct = new KToggleAction(i18n("Show Melody Editor"), "melodyeditor",
460
SHIFT + Key_M, this, SLOT(viewMelodyEditor()),
461
actionCollection(), "view_melodyEditor");
462
viewScoreAct = new KToggleAction(i18n("Show Score"), "score", SHIFT + Key_S,
463
this, SLOT(viewScore()),
464
actionCollection(), "view_score");
467
trkNewAct = new KAction(i18n("&New..."), 0, sv, SLOT(trackNew()),
468
actionCollection(), "track_new");
469
trkDeleteAct = new KAction(i18n("&Delete"), 0, sv, SLOT(trackDelete()),
470
actionCollection(), "track_delete");
471
trkBassLineAct = new KAction(i18n("&Generate Bass Line"), 0, sv, SLOT(trackBassLine()),
472
actionCollection(), "track_bassline");
473
trkPropAct = new KAction(i18n("P&roperties..."), 0, sv, SLOT(trackProperties()),
474
actionCollection(), "track_properties");
475
rhythmerAct = new KAction(i18n("&Rhythm..."), "rhythmer", SHIFT + Key_R,
476
sv->tv, SLOT(rhythmer()), actionCollection(), "rhythmer");
477
insChordAct = new KAction(i18n("&Chord..."), "chord", SHIFT + Key_C,
478
sv->tv, SLOT(insertChord()), actionCollection(), "insert_chord");
480
saveOptionAct = new KAction(i18n("&Save Options"), 0, this,
481
SLOT(saveOptions()), actionCollection(), "save_options");
483
arrTrkAct = new KAction(i18n("&Arrange Track"), SHIFT + Key_A, sv->tv,
484
SLOT(arrangeTracks()), actionCollection(), "arrange_trk");
486
// LESS THAN TRIVIAL MOVING STUFF ACTIONS
487
(void) new KAction(i18n("Transpose up"), 0, CTRL + Key_Up,
488
sv->tv, SLOT(transposeUp()), actionCollection(), "transpose_up");
489
(void) new KAction(i18n("Transpose down"), 0, CTRL + Key_Down,
490
sv->tv, SLOT(transposeDown()), actionCollection(), "transpose_down");
493
(void) new KAction(i18n("Whole"), "note1", CTRL + Key_1,
494
sv->tv, SLOT(setLength1()), actionCollection(), "set_len1");
495
(void) new KAction("1/2", "note2", CTRL + Key_2,
496
sv->tv, SLOT(setLength2()), actionCollection(), "set_len2");
497
(void) new KAction("1/4", "note4", CTRL + Key_3,
498
sv->tv, SLOT(setLength4()), actionCollection(), "set_len4");
499
(void) new KAction("1/8", "note8", CTRL + Key_4,
500
sv->tv, SLOT(setLength8()), actionCollection(), "set_len8");
501
(void) new KAction("1/16", "note16", CTRL + Key_5,
502
sv->tv, SLOT(setLength16()), actionCollection(), "set_len16");
503
(void) new KAction("1/32", "note32", CTRL + Key_6,
504
sv->tv, SLOT(setLength32()), actionCollection(), "set_len32");
505
(void) new KAction(i18n("Dotted note"), "dotted_note", Key_Period,
506
sv->tv, SLOT(dotNote()), actionCollection(), "dotted_note");
507
(void) new KAction(i18n("Triplet note"), "triplet", Key_T,
508
sv->tv, SLOT(tripletNote()), actionCollection(), "triplet");
509
(void) new KAction(i18n("More duration"), 0, Key_Equal,
510
sv->tv, SLOT(keyPlus()), actionCollection(), "more_duration");
511
(void) new KAction(i18n("Less duration"), 0, Key_Minus,
512
sv->tv, SLOT(keyMinus()), actionCollection(), "less_duration");
515
keySigAct = new KAction(i18n("Key signature"), "keysig", SHIFT + Key_K,
516
sv->tv, SLOT(keySig()), actionCollection(), "key_sig");
517
timeSigAct = new KAction(i18n("Time signature"), "timesig", SHIFT + Key_T,
518
sv->tv, SLOT(timeSig()), actionCollection(), "time_sig");
519
arcAct = new KAction(i18n("Link with previous column"), "arc", Key_L,
520
sv->tv, SLOT(linkPrev()), actionCollection(), "link_prev");
521
legatoAct = new KAction(i18n("Legato (hammer on/pull off)"), "fx_legato", Key_P,
522
sv->tv, SLOT(addLegato()), actionCollection(), "fx_legato");
523
slideAct = new KAction(i18n("Slide"), "fx_slide", Key_S,
524
sv->tv, SLOT(addSlide()), actionCollection(), "fx_slide");
525
letRingAct = new KAction(i18n("Let Ring"), "fx_let_ring", Key_I,
526
sv->tv, SLOT(addLetRing()), actionCollection(), "fx_let_ring");
527
natHarmAct = new KAction(i18n("Natural harmonic"), "fx_harmonic", Key_H,
528
sv->tv, SLOT(addHarmonic()), actionCollection(), "fx_nat_harm");
529
artHarmAct = new KAction(i18n("Artificial harmonic"), "fx_harmonic", Key_R,
530
sv->tv, SLOT(addArtHarm()), actionCollection(), "fx_art_harm");
531
palmMuteAct = new KAction(i18n("Palm muting"), "fx_palmmute", Key_M,
532
sv->tv, SLOT(palmMute()), actionCollection(), "fx_palmmute");
533
(void) new KAction(i18n("Dead note"), 0, Key_X,
534
sv->tv, SLOT(deadNote()), actionCollection(), "deadnote");
536
// SET UP 'Note Names'
539
midiPlaySongAct = new KAction(i18n("&Play / stop"), "1rightarrow", Key_Space,
540
sv, SLOT(playSong()), actionCollection(), "midi_playsong");
541
midiStopPlayAct = new KAction(i18n("&Stop"), "player_stop", CTRL + SHIFT + Key_P,
542
sv, SLOT(stopPlay()), actionCollection(), "midi_stopplay");
544
midiPlaySongAct->setEnabled(FALSE);
545
midiStopPlayAct->setEnabled(FALSE);
549
void KGuitarPart::setupAccels()
552
mainAccel = new KAccel(sv->tv);
555
mainAccel->insert("prev_column", i18n("Move cursor left"), QString::null,
556
Key_Left, sv->tv, SLOT(keyLeft()));
557
mainAccel->insert("next_column", i18n("Move cursor right"), QString::null,
558
Key_Right, sv->tv, SLOT(keyRight()));
559
mainAccel->insert("start_bar", i18n("Move cursor to the beginning of bar"), QString::null,
560
Key_Home, sv->tv, SLOT(keyHome()));
561
mainAccel->insert("end_bar", i18n("Move cursor to the end of bar"), QString::null,
562
Key_End, sv->tv, SLOT(keyEnd()));
563
mainAccel->insert("prev_bar", i18n("Move cursor to the previous bar"), QString::null,
564
CTRL + Key_Left, sv->tv, SLOT(keyLeftBar()));
565
mainAccel->insert("next_bar", i18n("Move cursor to the next bar"), QString::null,
566
CTRL + Key_Right, sv->tv, SLOT(keyRightBar()));
567
mainAccel->insert("start_track", i18n("Move cursor to the beginning of track"), QString::null,
568
CTRL + Key_Home, sv->tv, SLOT(keyCtrlHome()));
569
mainAccel->insert("end_track", i18n("Move cursor to the end of track"), QString::null,
570
CTRL + Key_End, sv->tv, SLOT(keyCtrlEnd()));
571
mainAccel->insert("select_prev_column", i18n("Move and select left"), QString::null,
572
SHIFT + Key_Left, sv->tv, SLOT(selectLeft()));
573
mainAccel->insert("select_next_column", i18n("Move and select right"), QString::null,
574
SHIFT + Key_Right, sv->tv, SLOT(selectRight()));
575
mainAccel->insert("key_up", i18n("Move cursor up"), QString::null,
576
Key_Up, sv->tv, SLOT(moveUp()));
577
mainAccel->insert("key_down", i18n("Move cursor down"), QString::null,
578
Key_Down, sv->tv, SLOT(moveDown()));
581
mainAccel->insert("key_del", i18n("Delete note"), QString::null,
582
Key_Delete, sv->tv, SLOT(deleteNote()));
583
mainAccel->insert("key_CtrlDel", i18n("Delete column"), QString::null,
584
CTRL + Key_Delete, sv->tv, SLOT(deleteColumn()));
585
mainAccel->insert("key_ins", i18n("Insert column"), QString::null,
586
Key_Insert, sv->tv, SLOT(insertColumn()));
588
// ...FOR KEY '0' - '9'
589
mainAccel->insert("key_1", i18n("Key 1"), QString::null, Key_1, sv->tv, SLOT(key1()));
590
mainAccel->insert("key_2", i18n("Key 2"), QString::null, Key_2, sv->tv, SLOT(key2()));
591
mainAccel->insert("key_3", i18n("Key 3"), QString::null, Key_3, sv->tv, SLOT(key3()));
592
mainAccel->insert("key_4", i18n("Key 4"), QString::null, Key_4, sv->tv, SLOT(key4()));
593
mainAccel->insert("key_5", i18n("Key 5"), QString::null, Key_5, sv->tv, SLOT(key5()));
594
mainAccel->insert("key_6", i18n("Key 6"), QString::null, Key_6, sv->tv, SLOT(key6()));
595
mainAccel->insert("key_7", i18n("Key 7"), QString::null, Key_7, sv->tv, SLOT(key7()));
596
mainAccel->insert("key_8", i18n("Key 8"), QString::null, Key_8, sv->tv, SLOT(key8()));
597
mainAccel->insert("key_9", i18n("Key 9"), QString::null, Key_9, sv->tv, SLOT(key9()));
598
mainAccel->insert("key_0", i18n("Key 0"), QString::null, Key_0, sv->tv, SLOT(key0()));
601
void KGuitarPart::clipboardDataChanged()
603
KAction *paste = actionCollection()->action(KStdAction::stdName(KStdAction::Paste));
606
paste->setEnabled(TrackDrag::canDecode(QApplication::clipboard()->data()));
609
void KGuitarPart::updateStatusBar()
612
tmp.setNum(sv->tv->trk()->xb + 1);
613
tmp = i18n("Bar: ") + tmp;
614
emit setStatusBarText(tmp);