Newer
Older
/*
==============================================================================
This file was auto-generated by the Jucer!
It contains the basic outline for a simple desktop window.
==============================================================================
*/
#include "MainWindow.h"
#include <stdio.h>
//==============================================================================
MainWindow::MainWindow()
: DocumentWindow (JUCEApplication::getInstance()->getApplicationName(),
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
125
126
127
128
129
130
131
132
133
134
DocumentWindow::allButtons)
{
centreWithSize (500, 400);
//setBounds(0,0,500,400);
setResizable (true, false);
// constraining size doesn't seem to work:
//setResizeLimits(500, 400, 10000, 10000);
//ComponentBoundsConstrainer* cbc = getConstrainer();
//cbc->setMinimumWidth(300);
//cbc->setMinimumHeight(200);
// Create ProcessorGraph and AudioComponent, and connect them.
// Callbacks will be set by the play button in the control panel
processorGraph = new ProcessorGraph();
audioComponent = new AudioComponent();
audioComponent->connectToProcessorGraph(processorGraph);
setContentComponent (new UIComponent(processorGraph, audioComponent), true, true);
loadWindowBounds();
setVisible (true);
}
MainWindow::~MainWindow()
{
saveWindowBounds();
processorGraph->saveState();
audioComponent->disconnectProcessorGraph();
deleteAndZero(processorGraph);
deleteAndZero(audioComponent);
setContentComponent (0);
}
void MainWindow::closeButtonPressed()
{
if (audioComponent->callbacksAreActive()) {
audioComponent->endCallbacks();
processorGraph->disableProcessors();
}
JUCEApplication::getInstance()->systemRequestedQuit();
}
void MainWindow::saveWindowBounds()
{
std::cout << "Saving window bounds." << std::endl;
File file = File("./windowState.xml");
XmlElement* xml = new XmlElement("MAINWINDOW");
XmlElement* bounds = new XmlElement("BOUNDS");
bounds->setAttribute("x",getScreenX());
bounds->setAttribute("y",getScreenY());
bounds->setAttribute("w",getWidth());
bounds->setAttribute("h",getHeight());
bounds->setAttribute("fullscreen",isFullScreen());
xml->addChildElement(bounds);
String error;
if (! xml->writeToFile (file, String::empty))
error = "Couldn't write to file";
delete xml;
}
void MainWindow::loadWindowBounds()
{
std::cout << "Loading window bounds." << std::endl;
File file = File("./windowState.xml");
XmlDocument doc (file);
XmlElement* xml = doc.getDocumentElement();
// if (xml == 0 || ! xml->hasTagName (T("MAINWINDOW")))
// {
// delete xml;
// // return "Not a valid file.";
// }
String description;// = T(" ");
forEachXmlChildElement (*xml, e)
{
int x = e->getIntAttribute("x");
int y = e->getIntAttribute("y");
int w = e->getIntAttribute("w");
int h = e->getIntAttribute("h");
bool fs = e->getBoolAttribute("fullscreen");
setTopLeftPosition(x,y);
getContentComponent()->setBounds(0,0,w,h);
//setFullScreen(fs);
}
delete xml;
// return "Everything went ok.";
}