File: main.cpp

package info (click to toggle)
tiatracker 1.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,664 kB
  • sloc: cpp: 8,875; asm: 664; makefile: 8
file content (124 lines) | stat: -rw-r--r-- 4,630 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* TIATracker, (c) 2016 Andre "Kylearan" Wichmann.
 * Website: https://bitbucket.org/kylearan/tiatracker
 * Email: andre.wichmann@gmx.de
 * See the file "license.txt" for information on usage and redistribution
 * of this file.
 */

#include "mainwindow.h"
#include <QApplication>
#include <QFile>
#include <QString>
#include <QComboBox>
#include <QThread>

#include "tiasound/tiasound.h"
#include "pianokeyboard.h"
#include "envelopeshaper.h"
#include "track/track.h"
#include "instrumentstab.h"
#include "percussiontab.h"
#include "tracktab.h"
#include "emulation/player.h"
#include <QThread>
#include "track/note.h"
#include "track/pattern.h"
#include "track/sequence.h"
#include "track/sequenceentry.h"
#include <QFile>
#include <QJsonObject>
#include <QJsonDocument>
#include "timeline.h"
#include <iostream>
#include <patterneditor.h>
#include <QCheckBox>
#include "optionstab.h"
#include <QTextStream>


#include "SDL.h"
#undef main
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    // Load and set stylesheet
    QFile styleFile(":/style.qss");
    styleFile.open(QFile::ReadOnly);
    a.setStyleSheet(styleFile.readAll());

    // Track
    Track::Track myTrack{};
    myTrack.newTrack();

    // GUI
    MainWindow::loadKeymap();
    MainWindow w;
    w.registerTrack(&myTrack);

    InstrumentsTab *it = w.findChild<InstrumentsTab *>("tabInstruments");
    it->registerTrack(&myTrack);
    it->initInstrumentsTab();
    it->updateInstrumentsTab();

    PercussionTab *pt = w.findChild<PercussionTab *>("tabPercussion");
    pt->registerTrack(&myTrack);
    pt->initPercussionTab();
    pt->updatePercussionTab();

    TrackTab *tt = w.findChild<TrackTab *>("tabTrack");
    tt->registerTrack(&myTrack);
    tt->registerPitchGuide(w.getPitchGuide());
    tt->initTrackTab();
    tt->updateTrackTab();

    OptionsTab *ot = w.findChild<OptionsTab *>("tabOptions");
    ot->registerTrack(&myTrack);
    ot->initOptionsTab();
    ot->updateOptionsTab();

    w.initConnections();

    /* Create and initialize player thread */
    Emulation::Player *tiaPlayer = new Emulation::Player(&myTrack);
    QThread *thread = new QThread();
    QObject::connect(&w, SIGNAL(initPlayerTimer()), tiaPlayer, SLOT(startTimer()));
    QObject::connect(&w, SIGNAL(stopPlayerTimer()), tiaPlayer, SLOT(stopTimer()));
    tiaPlayer->moveToThread(thread);
    QObject::connect(&w, SIGNAL(playInstrument(Track::Instrument*,int)), tiaPlayer, SLOT(playInstrument(Track::Instrument*,int)));
    QObject::connect(&w, SIGNAL(playInstrumentOnce(Track::Instrument*,int)), tiaPlayer, SLOT(playInstrumentOnce(Track::Instrument*,int)));
    QObject::connect(&w, SIGNAL(stopInstrument()), tiaPlayer, SLOT(stopInstrument()));
    QObject::connect(pt, SIGNAL(playWaveform(TiaSound::Distortion,int,int)), tiaPlayer, SLOT(playWaveform(TiaSound::Distortion,int,int)));
    QObject::connect(&w, SIGNAL(playPercussion(Track::Percussion*)), tiaPlayer, SLOT(playPercussion(Track::Percussion*)));
    QObject::connect(&w, SIGNAL(stopPercussion()), tiaPlayer, SLOT(stopPercussion()));
    QObject::connect(&w, SIGNAL(playTrack(int,int)), tiaPlayer, SLOT(playTrack(int,int)));
    QObject::connect(&w, SIGNAL(stopTrack()), tiaPlayer, SLOT(stopTrack()));
    Timeline *tl = w.findChild<Timeline *>("trackTimeline");
    PatternEditor *editor = w.findChild<PatternEditor *>("trackEditor");
    QObject::connect(tiaPlayer, SIGNAL(newPlayerPos(int,int)), tl, SLOT(playerPosChanged(int,int)));
    QObject::connect(tiaPlayer, SIGNAL(newPlayerPos(int,int)), editor, SLOT(newPlayerPos(int,int)));
    QObject::connect(tiaPlayer, SIGNAL(invalidNoteFound(int,int,int,QString)), tt, SLOT(invalidNoteFound(int,int,int,QString)));
    QObject::connect(tt, SIGNAL(stopTrack()), tiaPlayer, SLOT(stopTrack()));
    QObject::connect(editor, SIGNAL(editChannelChanged(int)), tiaPlayer, SLOT(selectedChannelChanged(int)));
    QCheckBox *cbLoop = w.findChild<QCheckBox *>("checkBoxLoop");
    QObject::connect(cbLoop, SIGNAL(toggled(bool)), tiaPlayer, SLOT(toggleLoop(bool)));
    QObject::connect(ot, SIGNAL(setTVStandard(int)), tiaPlayer, SLOT(setTVStandard(int)));

    pt->connectPlayer(tiaPlayer);
    tt->registerPlayer(tiaPlayer);
    editor->registerPlayer(tiaPlayer);

    thread->start(QThread::HighestPriority);
    w.initPlayer();

    w.updateAllTabs();

    // Shrink window size to minimum and show
    w.resize(0, 0);
    w.show();

    int result = a.exec();
    w.stopPlayer();
    delete tiaPlayer;
    return result;
}