-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
172 lines (143 loc) · 4.54 KB
/
main.cpp
File metadata and controls
172 lines (143 loc) · 4.54 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <Render.h>
#include <AudioManip.h>
#include <Application.h>
#include <iostream>
int main(int argc, const char* argv[])
{
// Initialisation COM
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (FAILED(hr))
{
std::cout << "Error while COM init, error : " << hr << std::endl;
return 1;
}
IXAudio2* pXAudio = nullptr;
hr = XAudio2Create(&pXAudio, 0, XAUDIO2_DEFAULT_PROCESSOR);
if (FAILED(hr))
{
std::cout << "Error while creating XAudio instance, error : " << hr << std::endl;
return 1;
}
IXAudio2MasteringVoice* pMasterVoice = nullptr;
hr = pXAudio->CreateMasteringVoice(&pMasterVoice);
if (FAILED(hr))
{
std::cout << "Error while creating Master voice, error : " << hr << std::endl;
return 1;
}
sf::RenderWindow* pWindow = new sf::RenderWindow(sf::VideoMode({ 1920, 1080}), "AudioEditor", sf::State::Windowed);
sf::RectangleShape brush;
sf::Texture goated;
if (goated.loadFromFile("res/goat.gif") == false) {
std::cout << "ff quitte le projet" << std::endl;
}
goated.setRepeated(true);
sf::Texture tilemap;
if (tilemap.loadFromFile("res/tilemap.bmp") == false) {
std::cout << "ff quitte le projet" << std::endl;
}
tilemap.setRepeated(true);
sf::Texture cinema;
if (cinema.loadFromFile("res/cinema.gif") == false) {
std::cout << "ff quitte le projet" << std::endl;
}
cinema.setRepeated(true);
// === INFINITE CANVAS ===
InfiniteCanvasDescriptor RootDesc{};
RootDesc.CanvasWidth = 1500;
RootDesc.CanvasHeight = 1080;
RootDesc.CanvasPosition = { 420,0 };
RootDesc.CanvasBackgroundColor = sf::Color(25, 0, 54);
RootDesc.CanvasBorder.Color = sf::Color::Magenta;
RootDesc.CanvasBorder.Thickness = 4.0f;
RootDesc.CanvasTexture = &tilemap;
auto root = CreateRoot<InfiniteCanvas>(&RootDesc);
AudioFileDescriptor FileDesc{};
FileDesc.CanvasWidth = 400;
FileDesc.CanvasHeight = 200;
FileDesc.pFilePath = "res/Fight for the Win.wav";
FileDesc.pXAudio = pXAudio;
FileDesc.pMasterVoice = pMasterVoice;
auto audio_file = AddChildTo<AudioFile>(root, &FileDesc);
FFTVisualDescriptor FFTDesc{};
FFTDesc.CanvasWidth = 400;
FFTDesc.CanvasHeight = 100;
FFTDesc.CanvasPosition = { 400, 200 };
FFTDesc.pAudioBuffer = audio_file->GetBuffer(0);
FFTDesc.AudioBufferOwner = false;
FFTDesc.AudioBufferSampleRate = audio_file->GetSampleRate();
FFTDesc.AudioBufferSize = audio_file->GetBufferSize(0);
auto fft = AddChildTo<FFTVisual>(root, &FFTDesc);
CanvasDescriptor desc{};
desc.CanvasWidth = 120;
desc.CanvasHeight = 100;
desc.CanvasPosition = { 2500, 500 };
desc.CanvasTexture = &goated;
auto canvas = AddChildTo<Canvas>(root, &desc);
CanvasDescriptor desc2 {};
desc2.CanvasWidth = 150;
desc2.CanvasHeight = 100;
desc2.CanvasPosition = { 2500, 700 };
desc2.CanvasTexture = &cinema;
auto canvas3 = AddChildTo<Canvas>(root, &desc2);
// === INFO BAR ===
InfoBarDescriptor infobarDesc{};
infobarDesc.CanvasWidth = 420;
infobarDesc.CanvasHeight = 300;
infobarDesc.pInfiniteCanvas = root;
auto infobar = CreateRoot<InfoBar>(&infobarDesc);
// === TOOL BAR ===
ToolBarDescriptor ToolDesc{};
ToolDesc.CanvasWidth = 420;
ToolDesc.CanvasHeight = 780;
ToolDesc.CanvasPosition = { 0,300 };
ToolDesc.CanvasBackgroundColor = sf::Color(24, 0, 54);
ToolDesc.pRoot = root;
ToolDesc.pXAudio = pXAudio;
ToolDesc.pMasterVoice = pMasterVoice;
auto toolbar = CreateRoot<ToolBar>(&ToolDesc);
WidgetUpdateContext ctx{};
while (pWindow->isOpen())
{
sf::Vector2f new_mouse_pos = (sf::Vector2f)sf::Mouse::getPosition(*pWindow);
ctx.mouseDelta = new_mouse_pos - ctx.mousePos;
ctx.mousePos = new_mouse_pos;
bool down[3] = {
sf::Mouse::isButtonPressed(sf::Mouse::Button::Left),
sf::Mouse::isButtonPressed(sf::Mouse::Button::Right),
sf::Mouse::isButtonPressed(sf::Mouse::Button::Middle)
};
TMM_ITER(i, 3)
{
ctx.mouseClicked[i] = ctx.mouseDown[i] == false && down[i];
ctx.mouseDown[i] = down[i];
}
while (std::optional<sf::Event> event = pWindow->pollEvent())
{
if (event->is<sf::Event::Closed>() || sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape))
{
pWindow->close();
break;
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Backspace)) {
Widget* pSelected = root->GetChildSelected();
root->SetNoSelected();
if (pSelected != nullptr) {
root->RemoveChild(pSelected);
}
}
pWindow->clear();
root->Update(ctx);
root->Draw(pWindow, brush);
infobar->Update(ctx);
infobar->Draw(pWindow, brush);
toolbar->Update(ctx);
toolbar->Draw(pWindow, brush);
pWindow->display();
}
pMasterVoice->DestroyVoice();
pXAudio->Release();
CoUninitialize();
return 0;
}