-
Notifications
You must be signed in to change notification settings - Fork 23
/
ofApp.cpp
2104 lines (1738 loc) · 85.9 KB
/
ofApp.cpp
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*==============================================================================
Mosaic: Live Visual Patching Creative-Coding Platform
Copyright (c) 2018 Emanuele Mazza aka n3m3da <emanuelemazza@d3cod3.org>
Mosaic is distributed under the MIT License. This gives everyone the
freedoms to use Mosaic in any context: commercial or non-commercial,
public or private, open or closed source.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
See https://github.com/d3cod3/Mosaic for documentation
==============================================================================*/
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
///////////////////////////////////////////
// OF Stuff
ofSetEscapeQuitsApp(false);
ofSetVerticalSync(true);
ofEnableAntiAliasing();
ofSetLogLevel(PACKAGE,OF_LOG_NOTICE);
ofRegisterURLNotification(this);
initDataFolderFromBundle();
///////////////////////////////////////////
// TIMING
mosaicFPS = 60;
mosaicTiming.setFramerate(mosaicFPS);
mosaicBPM = 120;
// RETINA FIX
retinaScale = dynamic_pointer_cast<ofAppGLFWWindow>(ofGetCurrentWindow())->getPixelScreenCoordScale();
isRetina = false;
if(retinaScale > 1){
isRetina = true;
}
// LOGGER
isInited = false;
isWindowResized = false;
isLoggerON = false;
mosaicLoggerChannel = shared_ptr<MosaicLoggerChannel>(new MosaicLoggerChannel());
ofSetLoggerChannel(mosaicLoggerChannel);
ofLog(OF_LOG_NOTICE,"%s | %s <%s>",WINDOW_TITLE,DESCRIPTION,MOSAIC_WWW);
ofLog(OF_LOG_NOTICE," an open project by Emanuele Mazza aka n3m3da");
ofLog(OF_LOG_NOTICE,"Developers: %s",MOSAIC_DEVELOPERS);
ofLog(OF_LOG_NOTICE,"This project deals with the idea of integrate/amplify human-machine communication, offering a real-time flowchart based visual interface for high level creative coding.\nAs live-coding scripting languages offer a high level coding environment, ofxVisualProgramming and the Mosaic Project as his parent layer container,\naim at a high level visual-programming environment, with embedded multi scripting languages availability (Processing/Java, Lua, Python, GLSL and BASH).\n");
// Visual Programming Environment Load
// ImGui
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.IniFilename = nullptr;
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.MouseDrawCursor = false;
// double font oversampling (default 3) for canvas zoom
ImFontConfig font_config;
font_config.OversampleH = 6;
font_config.OversampleV = 6;
ofFile fileToRead1(ofToDataPath(MAIN_FONT));
string absPath1 = fileToRead1.getAbsolutePath();
ofFile fileToRead2(ofToDataPath(LIVECODING_FONT));
string absPath2 = fileToRead2.getAbsolutePath();
if(isRetina){
io.Fonts->AddFontFromFileTTF(absPath2.c_str(),30.0f,&font_config); // code editor font
io.Fonts->AddFontFromFileTTF(absPath1.c_str(),26.0f,&font_config); // GUI font
}else{
io.Fonts->AddFontFromFileTTF(absPath2.c_str(),18.0f,&font_config); // code editor font
io.Fonts->AddFontFromFileTTF(absPath1.c_str(),14.0f,&font_config); // GUI font
}
// merge in icons from Font Awesome
static const ImWchar icons_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
if(isRetina){
io.Fonts->AddFontFromFileTTF( FONT_ICON_FILE_NAME_FAS, 24.0f, &icons_config, icons_ranges );
}else{
io.Fonts->AddFontFromFileTTF( FONT_ICON_FILE_NAME_FAS, 16.0f, &icons_config, icons_ranges );
}
ImFont* defaultfont = io.Fonts->Fonts[io.Fonts->Fonts.Size - 1];
io.FontDefault = defaultfont;
mainTheme = new MosaicTheme();
mainMenu.setup(mainTheme,false);
visualProgramming = new ofxVisualProgramming();
visualProgramming->setRetina(isRetina);
visualProgramming->setup( &mainMenu );
visualProgramming->canvasViewport.set(glm::vec2(0,20*retinaScale), glm::vec2(ofGetWidth(), ofGetHeight()-(20*retinaScale)));
patchToLoad = "";
loadNewPatch = false;
isAutoloadedPatch = false;
// GUI
mosaicLogo = new ofImage("images/logo_1024_bw.png");
mosaicLogoID = mainMenu.loadImage(*mosaicLogo);
showRightClickMenu = false;
createSearchedObject = false;
showAboutWindow = false;
// VIDEO EXPORTER ( documenting patches, tutorials, etc...)
recordFilepath = "";
exportVideoFlag = false;
recButtonLabel = "REC";
// PATCH WINDOW ( MAIN ) VIDEO EXPORTER
actualSubtitle = "";
showSubtitler = false;
showingClickAnimation = false;
mouseClickRadius = 0.0f;
showMouseOnRec = false;
captureFbo.allocate( ofGetWindowWidth(), ofGetWindowHeight(), GL_RGB );
recorder.setup(true, false, glm::vec2(ofGetWindowWidth(), ofGetWindowHeight())); // record video only
recorder.setOverWrite(true);
#if defined(TARGET_OSX)
recorder.setFFmpegPath(ofToDataPath("ffmpeg/osx/ffmpeg",true));
#elif defined(TARGET_WIN32)
recorder.setFFmpegPath(ofToDataPath("ffmpeg/win/ffmpeg.exe",true));
#endif
// CODE EDITOR
luaLang = TextEditor::LanguageDefinition::Lua();
glslLang = TextEditor::LanguageDefinition::GLSL();
pythonLang= TextEditor::LanguageDefinition::Python();
bashLang = TextEditor::LanguageDefinition::Bash();
initScriptLanguages();
actualCodeEditor = 0;
actualEditedFilePath = "";
actualEditedFileName = "";
scriptToRemoveFromCodeEditor = "";
isCodeEditorON = false;
isOverCodeEditor = false;
#ifdef TARGET_LINUX
shortcutFunc = "CTRL";
#elif defined(TARGET_OSX)
shortcutFunc = "CMD";
#elif defined(TARGET_WIN32)
shortcutFunc = "CTRL";
#endif
// ASSET LIBRARY
assetWatcher.start();
selectedFile = "";
isAssetFolderInited = false;
isAssetLibraryON = false;
isOverAssetLibrary = false;
isDeleteModalON = false;
// NET
isInternetAvailable = false;
isCheckingRelease = false;
// Check for updates
lastRelease = VERSION;
isInternetAvailable = checkInternetReachability();
saveNewScreenshot = false;
lastScreenshot = "";
waitForScreenshotTime = 200;
resetScreenshotTime = ofGetElapsedTimeMillis();
// AUTOLOAD PATCH ( if configured )
checkAutoloadConfig();
}
//--------------------------------------------------------------
void ofApp::update(){
windowTitle = visualProgramming->currentPatchFile+" - "+WINDOW_TITLE;
ofSetWindowTitle(windowTitle);
// Visual Programming Environment
if(mosaicTiming.tick()){
visualProgramming->update();
visualProgramming->canvasViewport.set(glm::vec2(0,20*retinaScale), glm::vec2(ofGetWidth(), ofGetHeight()-(20*retinaScale)));
refreshScriptTabs();
}
// init start empty patch
if(loadNewPatch){
loadNewPatch = false;
if(patchToLoad != ""){
visualProgramming->preloadPatch(patchToLoad);
mosaicBPM = visualProgramming->bpm;
ofFile temp(patchToLoad);
assetFolder.reset();
assetFolder.listDir(temp.getEnclosingDirectory()+"data/");
assetFolder.sort();
assetWatcher.removeAllPaths();
assetWatcher.addPath(temp.getEnclosingDirectory()+"data/");
}
}
// autoload patch on startup
if(autoloadPatchFile != "" && isAutoloadedPatch){
if(ofGetElapsedTimeMillis() - autoloadStartTime > waitForAutoload){
isAutoloadedPatch = false;
visualProgramming->preloadPatch(autoloadPatchFile);
mosaicBPM = visualProgramming->bpm;
ofFile temp(autoloadPatchFile);
assetFolder.listDir(temp.getEnclosingDirectory()+"data/");
assetFolder.sort();
assetWatcher.removeAllPaths();
assetWatcher.addPath(temp.getEnclosingDirectory()+"data/");
}
}
// listen for editing scripts external changes
if(codeWatchers.size() > 0){
for(map<string,PathWatcher*>::iterator it = codeWatchers.begin(); it != codeWatchers.end(); it++ ){
while(it->second->waitingEvents()) {
pathChanged(it->second->nextEvent());
}
}
}
// listen for asset folder changes
while(assetWatcher.waitingEvents()) {
pathChanged(assetWatcher.nextEvent());
}
if(isWindowResized){
isWindowResized = false;
visualProgramming->updateCanvasViewport();
}
if(!isInited){
isInited = true;
// RETINA FIX
if(isRetina){
ofSetWindowShape(ofGetScreenWidth()-8,ofGetScreenHeight());
}else{
if(ofGetScreenWidth() >= 1920){ // DUAL HEAD, TRIPLE HEAD
ofSetWindowShape(1920-4,ofGetScreenHeight());
}else{ // STANDARD SCREEN
ofSetWindowShape(ofGetScreenWidth()-4,ofGetScreenHeight());
}
}
/*if(isRetina){ // RETINA SCREEN
ofSetWindowShape(ofGetScreenWidth()-8,ofGetScreenHeight());
isRetina = true;
}else if(ofGetScreenWidth() >= 1920){ // DUAL HEAD, TRIPLE HEAD
ofSetWindowShape(1920-4,ofGetScreenHeight());
}else{ // STANDARD SCREEN
ofSetWindowShape(ofGetScreenWidth()-4,ofGetScreenHeight());
}*/
if(isRetina){
mainTheme->fixForRetinaScreen();
}
fileDialog.setIsRetina(isRetina);
}
if(ofGetElapsedTimeMillis() > 3000 && !isAssetFolderInited){
isAssetFolderInited = true;
assetFolder.reset();
assetFolder.listDir(ofToDataPath("temp/data/",true));
assetFolder.sort();
assetWatcher.addPath(ofToDataPath("temp/data/",true));
}
// NET
if(isInternetAvailable && !isCheckingRelease){
isCheckingRelease = true;
lastReleaseResp = ofLoadURLAsync("https://raw.githubusercontent.com/d3cod3/Mosaic/master/RELEASE.md","check_release_async");
}
// Screenshot
if(saveNewScreenshot){
if(ofGetElapsedTimeMillis()-resetScreenshotTime > waitForScreenshotTime){ // avoid imgui filebrowser
saveNewScreenshot = false;
if(lastScreenshot != ""){
ofFile file(lastScreenshot);
// force .jpg file extension
string finalPath = file.getAbsolutePath();
if(ofToUpper(file.getExtension()) != "JPG"){
finalPath += ".jpg";
}
ofImage tempScreenshot;
tempScreenshot.grabScreen(ofGetWindowRect().x,ofGetWindowRect().y,ofGetWindowWidth(),ofGetWindowHeight());
tempScreenshot.getPixels().swapRgb();
tempScreenshot.save(finalPath);
}
}
}
// Video Recording
if(recorder.isRecording()) {
static ofImage recordFrame;
recordFrame.grabScreen(ofGetWindowRect().x,ofGetWindowRect().y,ofGetWindowWidth(),ofGetWindowHeight());
captureFbo.begin();
ofClear(0,0,0,255);
ofSetColor(255);
recordFrame.draw(0,0,ofGetWindowWidth(),ofGetWindowHeight());
captureFbo.end();
reader.readToPixels(captureFbo, capturePix,OF_IMAGE_COLOR); // ofxFastFboReader
if(capturePix.getWidth() > 0 && capturePix.getHeight() > 0) {
recorder.addFrame(capturePix);
}
}
}
//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(20);
ofFill();
ofSetLineWidth(1);
// BACKGROUND GUI
// canvas grid (TouchDesigner style)
ofSetColor(255,255,255,6);
ofSetLineWidth(1);
for(int i=0;i<60;i++){
ofDrawLine(ofGetWindowWidth()/30 * i,0,ofGetWindowWidth()/30 * i,ofGetWindowHeight());
ofDrawLine(0,ofGetWindowWidth()/30 * i,ofGetWindowWidth(),ofGetWindowWidth()/30 * i);
}
// Logo
ofSetColor(255,255,255,16);
mosaicLogo->draw(ofGetWindowWidth()/2 - (128*retinaScale),(ofGetWindowHeight()- (240*retinaScale))/2 - (128*retinaScale),256*retinaScale,256*retinaScale);
// Mosaic Visual Programming
ofSetColor(255,255,255);
if(!visualProgramming->bLoadingNewPatch){
// draw main GUI interface
drawImGuiInterface();
// Draw to vp Gui
visualProgramming->draw();
// Manually render ImGui once ofxVP rendered to it.
mainMenu.draw();
}
// DSP flag
if(visualProgramming->dspON){
ofSetColor(ofColor::fromHex(0xFFD00B));
visualProgramming->font->drawString("DSP ON",10*retinaScale,ofGetHeight() - (6*retinaScale));
}else{
ofSetColor(ofColor::fromHex(0x777777));
visualProgramming->font->drawString("DSP OFF",10*retinaScale,ofGetHeight() - (6*retinaScale));
}
// Last LOG on bottom bar
string tmpMsg = mosaicLoggerChannel->GetLastLog();
if(tmpMsg.find("[warning") != std::string::npos) {
ofSetColor(255, 127, 0);
}else if(tmpMsg.find("[ error") != std::string::npos || tmpMsg.find("[ fatal") != std::string::npos) {
ofSetColor(255, 45, 45);
}else{
ofSetColor(220,220,220);
}
// FORCE CUSTOM VERBOSE
if(tmpMsg.find("[verbose]") != std::string::npos){
ofSetColor(60, 255, 60);
}
visualProgramming->font->drawString(tmpMsg,100*retinaScale,ofGetHeight() - (6*retinaScale));
// subtitler
if(showSubtitler){
ofSetColor(0,0,0,100);
ofDrawRectangle(0,ofGetWindowHeight()-(166*retinaScale),ofGetWindowWidth(),147*retinaScale);
ofSetColor(245);
// cut subtitle at second newline
int subLastPos = nthOccurrence(actualSubtitle,"\n",2);
string finalSubtitle = "";
if(subLastPos != -1){
finalSubtitle = actualSubtitle.substr(0,subLastPos);
}else{
finalSubtitle = actualSubtitle;
}
/*if(isRetina){
visualProgramming->font->drawString(finalSubtitle,0,ofGetHeight()-(100*retinaScale));
}else{
visualProgramming->font->drawString(finalSubtitle,0,ofGetHeight()-(100*retinaScale));
//visualProgramming->font->drawMultiLine(finalSubtitle,64,0,ofGetHeight()-(100*retinaScale),OF_ALIGN_HORZ_CENTER,ofGetWidth());
}*/
}
// mouse click on recording
if(showMouseOnRec && showingClickAnimation){ // && recorder.isRecording()
if(mouseClickRadius < 15.0f*retinaScale){
mouseClickRadius += 1.0f*retinaScale;
}else{
showingClickAnimation = false;
}
ofNoFill();
ofSetLineWidth(4);
ofSetColor(182,30,41,250);
ofDrawCircle(lastclickPos.x,lastclickPos.y,mouseClickRadius);
}
}
//--------------------------------------------------------------
void ofApp::drawImGuiInterface(){
mainMenu.begin();
{
// Fullscreen transparent DockSpace
static bool showDockspace = true;
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoBackground;
ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->GetWorkPos());
ImGui::SetNextWindowSize(ImVec2(viewport->GetWorkSize().x,viewport->GetWorkSize().y-(20*retinaScale)));
ImGui::SetNextWindowViewport(viewport->ID);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
ImGui::Begin("DockSpace", &showDockspace, window_flags);
ImGui::PopStyleVar(3);
ImGui::SetNextWindowBgAlpha(0.0f);
ImGui::DockSpace(ImGui::GetID("MosaicDockSpace"), ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_None|ImGuiDockNodeFlags_PassthruCentralNode);
ImGui::BeginMainMenuBar();
{
openPatch = false;
savePatchAs = false;
openAutoloadPatch = false;
takeScreenshot = false;
exportVideoFlag = false;
if(ImGui::BeginMenu( "File")){
if(ImGui::MenuItem( "New patch",ofToString(shortcutFunc+"+N").c_str())){
visualProgramming->newPatch();
ofFile temp(visualProgramming->currentPatchFile);
assetFolder.reset();
assetFolder.listDir(temp.getEnclosingDirectory()+"data/");
assetFolder.sort();
assetWatcher.removeAllPaths();
assetWatcher.addPath(temp.getEnclosingDirectory()+"data/");
}
ImGui::Separator();
if(ImGui::MenuItem( "Open patch" )){
openPatch = true;
}
ImGui::Separator();
if(ImGui::MenuItem( "Save patch As.." )){
savePatchAs = true;
}
ImGui::Spacing();
ImGui::Separator();
ImGui::Separator();
ImGui::Spacing();
if(ImGui::BeginMenu( "Autoload")){
if(ImGui::MenuItem( "Set autoload patch" )){
openAutoloadPatch = true;
}
ImGui::Separator();
if(ImGui::MenuItem( "Remove autoload patch" )){
autoloadPatchFile = "";
autoloadDelaySeconds = 1;
setAutoloadConfig();
}
ImGui::Spacing();
ImGui::Spacing();
if(ImGui::DragInt("Delay ( Seconds )",&autoloadDelaySeconds)){
if(autoloadDelaySeconds < 1){
autoloadDelaySeconds = 1;
}
}
ImGui::Spacing();
ImGui::Spacing();
if(autoloadPatchFile == ""){
ImGui::Text("no patch in autoload mode");
}else{
ImGui::Text("%s",_apf.getFileName().c_str());
if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s",_apf.getAbsolutePath().c_str());
}
ImGui::Spacing();
ImGui::Spacing();
if(ImGui::Button("APPLY",ImVec2(-1,26*retinaScale))){
setAutoloadConfig();
}
ImGui::EndMenu();
}
ImGui::Spacing();
ImGui::Separator();
ImGui::Separator();
ImGui::Spacing();
if(ImGui::MenuItem( "Quit",ofToString(shortcutFunc+"+Q").c_str())){
quitMosaic();
}
ImGui::EndMenu();
}
if(ImGui::BeginMenu( "Objects")){
ofxVPObjects::factory::objectCategories& objectsMatrix = ofxVPObjects::factory::getCategories();
for(ofxVPObjects::factory::objectCategories::iterator it = objectsMatrix.begin(); it != objectsMatrix.end(); ++it ){
#if !defined(TARGET_WIN32)
if(ImGui::BeginMenu(it->first.c_str())){
std::sort(it->second.begin(), it->second.end());
for(int j=0;j<static_cast<int>(it->second.size());j++){
if(it->second.at(j) != "audio device"){
if(ImGui::MenuItem(it->second.at(j).c_str())){
visualProgramming->addObject(it->second.at(j),ofVec2f(visualProgramming->canvas.getMovingPoint().x + 200,visualProgramming->canvas.getMovingPoint().y + 200));
}
}
}
ImGui::EndMenu();
}
#else
if(it->first != OFXVP_OBJECT_CAT_AUDIOANALYSIS && it->first != OFXVP_OBJECT_CAT_SOUND){
if(ImGui::BeginMenu(it->first.c_str())){
std::sort(it->second.begin(), it->second.end());
for(int j=0;j<static_cast<int>(it->second.size());j++){
if(it->second.at(j) != "audio device"){
if(ImGui::MenuItem(it->second.at(j).c_str())){
visualProgramming->addObject(it->second.at(j),ofVec2f(visualProgramming->canvas.getMovingPoint().x + 200,visualProgramming->canvas.getMovingPoint().y + 200));
}
}
}
ImGui::EndMenu();
}
}
#endif
}
ImGui::EndMenu();
}
if(ImGui::BeginMenu( "Examples")){
#if defined(TARGET_OSX)
examplesRoot.listDir(mosaicExamplesPath.string());
#else
examplesRoot.listDir(ofToDataPath("../examples"));
#endif
examplesRoot.sort();
for(int i=0;i<examplesRoot.getFiles().size();i++){
createDirectoryNode(examplesRoot.getFiles().at(i));
}
ImGui::EndMenu();
}
#if !defined(TARGET_WIN32)
if(ImGui::BeginMenu( "Sound")){
if(ImGui::Checkbox("DSP",&visualProgramming->dspON)){
if(visualProgramming->dspON){
visualProgramming->activateDSP();
}else{
visualProgramming->deactivateDSP();
}
}
ImGui::Spacing();
ImGui::Separator();
ImGui::Separator();
ImGui::Spacing();
if(ImGui::DragInt("TEMPO",&mosaicBPM,1.0f,1)){
visualProgramming->bpm = mosaicBPM;
visualProgramming->engine->sequencer.setTempo(mosaicBPM);
visualProgramming->setPatchVariable("bpm",mosaicBPM);
}
ImGui::Spacing();
ImGui::Separator();
ImGui::Separator();
ImGui::Spacing();
static int inDev = visualProgramming->audioGUIINIndex;
if(ofxImGui::VectorCombo("Input Device", &inDev,visualProgramming->audioDevicesStringIN)){
visualProgramming->setAudioInDevice(inDev);
}
static int outDev = visualProgramming->audioGUIOUTIndex;
if(ofxImGui::VectorCombo("Output Device", &outDev,visualProgramming->audioDevicesStringOUT)){
visualProgramming->setAudioOutDevice(outDev);
}
ImGui::EndMenu();
}
#endif
if(ImGui::BeginMenu( "System")){
if(ImGui::DragInt("FPS",&mosaicFPS,1.0f,1)){
setMosaicFrameRate(mosaicFPS);
}
ImGui::Spacing();
ImGui::Separator();
ImGui::Separator();
ImGui::Spacing();
ImGui::Spacing();
ImGui::Text("Desktop Recorder");
ImGui::Spacing();
if(ImGui::Button(ICON_FA_FILE_UPLOAD)){
exportVideoFlag = true;
}
ImGui::SameLine();
if(recordFilepath == ""){
ImGui::Text("Select file...");
}else{
ofFile tempFilename(recordFilepath);
ImGui::Text("%s",tempFilename.getFileName().c_str());
if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s",tempFilename.getAbsolutePath().c_str());
}
ImGui::Spacing();
ImGui::PushStyleColor(ImGuiCol_Button, VHS_RED);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, VHS_RED_OVER);
ImGui::PushStyleColor(ImGuiCol_ButtonActive, VHS_RED_OVER);
char tmp[256];
sprintf(tmp,"%s %s",ICON_FA_CIRCLE, recButtonLabel.c_str());
if(ImGui::Button(tmp,ImVec2(-1,26*retinaScale))){
if(recordFilepath != ""){
if(!recorder.isRecording()){
captureFbo.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGB );
recorder.setup(true, false, glm::vec2(ofGetWindowWidth(), ofGetWindowHeight())); // record video only
ofSetVerticalSync(false);
recorder.setOverWrite(true);
recorder.setVideoCodec("hevc"); // h265
recorder.setBitRate(20000);
recorder.startCustomRecord();
recButtonLabel = "STOP";
ofLog(OF_LOG_NOTICE,"START RECORDING MOSAIC WINDOW");
}else if(recorder.isRecording()){
ofSetVerticalSync(true);
recorder.stop();
recButtonLabel = "REC";
ofLog(OF_LOG_NOTICE,"FINISHED RECORDING MOSAIC WINDOW");
}
}else{
ofLog(OF_LOG_ERROR,"SELECT FILE BEFORE RECORD VIDEO!");
}
}
ImGui::PopStyleColor(3);
ImGui::Spacing();
ImGui::Separator();
ImGui::Separator();
ImGui::Spacing();
ImGui::Checkbox("Show mouse clicks",&showMouseOnRec);
ImGui::Spacing();
ImGui::Checkbox("Subtitler",&showSubtitler);
ImGui::Spacing();
ImGui::PushItemWidth(-1);
ImGui::InputTextMultiline("##subtitle",&actualSubtitle,ImVec2(-1,ImGui::GetFontSize()*3));
ImGui::PopItemWidth();
ImGui::Spacing();
ImGui::Separator();
ImGui::Separator();
ImGui::Spacing();
if(ImGui::Button("Screenshot", ImVec2(-1,26*retinaScale))){
takeScreenshot = true;
}
ImGui::EndMenu();
}
if(ImGui::BeginMenu( "View")){
ImGui::Checkbox("Asset Manager",&isAssetLibraryON);
ImGui::Checkbox("Code Editor",&isCodeEditorON);
ImGui::Checkbox("Inspector",&visualProgramming->inspectorActive);
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
ImGui::Checkbox("Logger",&isLoggerON);
ImGui::Checkbox("Profiler",&visualProgramming->profilerActive);
ImGui::EndMenu();
}
if(ImGui::BeginMenu( "Help")){
if(ImGui::MenuItem("Mosaic Github")){
ofLaunchBrowser("https://github.com/d3cod3/Mosaic");
}
if(ImGui::MenuItem("Mosaic Manual")){
ofLaunchBrowser("https://mosaic.d3cod3.org/manual/");
}
if(ImGui::MenuItem("Mosaic Reference")){
ofLaunchBrowser("https://mosaic.d3cod3.org/#reference");
}
ImGui::Spacing();
ImGui::Separator();
ImGui::Separator();
ImGui::Spacing();
if(ImGui::MenuItem("OF Reference")){
ofLaunchBrowser("https://openframeworks.cc/documentation/");
}
if(ImGui::MenuItem("ofxAddons")){
ofLaunchBrowser("http://ofxaddons.com/categories");
}
ImGui::Spacing();
ImGui::Separator();
ImGui::Separator();
ImGui::Spacing();
if(ImGui::MenuItem("About Mosaic")){
showAboutWindow = !showAboutWindow;
}
ImGui::EndMenu();
}
// File dialogs
if(openPatch) ImGui::OpenPopup("Open patch");
if(savePatchAs) ImGui::OpenPopup("Save patch");
if(openAutoloadPatch) ImGui::OpenPopup("Set autoload patch");
if(takeScreenshot) ImGui::OpenPopup("Take screenshot");
if(exportVideoFlag) ImGui::OpenPopup("Record video");
// open patch
if( fileDialog.showFileDialog("Open patch", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(FILE_DIALOG_WIDTH*retinaScale, FILE_DIALOG_HEIGHT*retinaScale), ".xml") ){
ofFile file(fileDialog.selected_path);
if (file.exists()){
string fileExtension = ofToUpper(file.getExtension());
if(fileExtension == "XML") {
ofxXmlSettings XML;
if (XML.loadFile(file.getAbsolutePath())){
if (XML.getValue("www","") == "https://mosaic.d3cod3.org"){
patchToLoad = file.getAbsolutePath();
loadNewPatch = true;
}else{
ofLog(OF_LOG_ERROR, "The opened file: %s, is not a Mosaic patch!",file.getAbsolutePath().c_str());
}
}
}
}
}
// set autoload patch
if( fileDialog.showFileDialog("Set autoload patch", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(FILE_DIALOG_WIDTH*retinaScale, FILE_DIALOG_HEIGHT*retinaScale), ".xml") ){
ofFile file(fileDialog.selected_path);
if (file.exists()){
string fileExtension = ofToUpper(file.getExtension());
if(fileExtension == "XML") {
ofxXmlSettings XML;
if (XML.loadFile(file.getAbsolutePath())){
if (XML.getValue("www","") == "https://mosaic.d3cod3.org"){
autoloadPatchFile = file.getAbsolutePath();
_apf.open(autoloadPatchFile);
}else{
ofLog(OF_LOG_ERROR, "The opened file: %s, is not a Mosaic patch!",file.getAbsolutePath().c_str());
}
}
}
}
}
// save patch
string newFileName = "mosaicPatch_"+ofGetTimestampString("%y%m%d")+".xml";
if( fileDialog.showFileDialog("Save patch", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ImVec2(FILE_DIALOG_WIDTH*retinaScale, FILE_DIALOG_HEIGHT*retinaScale), ".xml", newFileName) ){
ofFile file(fileDialog.selected_path);
visualProgramming->savePatchAs(file.getAbsolutePath());
assetFolder.reset();
assetFolder.listDir(visualProgramming->currentPatchFolderPath+"/data/");
assetFolder.sort();
assetWatcher.removeAllPaths();
assetWatcher.addPath(visualProgramming->currentPatchFolderPath+"/data/");
}
// take patch screenshot
string newShotName = "mosaicScreenshot_"+ofGetTimestampString("%y%m%d")+".jpg";
if( fileDialog.showFileDialog("Take screenshot", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ImVec2(FILE_DIALOG_WIDTH*retinaScale, FILE_DIALOG_HEIGHT*retinaScale), ".jpg", newShotName) ){
ofFile file(fileDialog.selected_path);
lastScreenshot = file.getAbsolutePath();
saveNewScreenshot = true;
resetScreenshotTime = ofGetElapsedTimeMillis();
}
// record video
#if defined(TARGET_WIN32)
string newRecordVideoName = "mosaicVideoRecorder_"+ofGetTimestampString("%y%m%d")+".avi";
if( fileDialog.showFileDialog("Record video", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ImVec2(FILE_DIALOG_WIDTH*retinaScale, FILE_DIALOG_HEIGHT*retinaScale), ".avi", newRecordVideoName) ){
ofFile file(fileDialog.selected_path);
recordFilepath = file.getAbsolutePath();
// check extension
if(fileDialog.ext != ".avi"){
recordFilepath += ".avi";
}
recorder.setOutputPath(recordFilepath);
recorder.setVideoCodec("hevc");
// prepare blank video file
recorder.startCustomRecord();
recorder.stop();
}
#else
string newRecordVideoName = "mosaicVideoRecorder_"+ofGetTimestampString("%y%m%d")+".mp4";
if( fileDialog.showFileDialog("Record video", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ImVec2(FILE_DIALOG_WIDTH*retinaScale, FILE_DIALOG_HEIGHT*retinaScale), ".mp4", newRecordVideoName) ){
ofFile file(fileDialog.selected_path);
recordFilepath = file.getAbsolutePath();
// check extension
if(fileDialog.ext != ".mp4"){
recordFilepath += ".mp4";
}
recorder.setOutputPath(recordFilepath);
recorder.setVideoCodec("hevc");
// prepare blank video file
recorder.startCustomRecord();
recorder.stop();
}
#endif
}
ImGui::EndMainMenuBar();
// About window
if(showAboutWindow){
//ImGui::SetNextWindowPos(ImVec2((ofGetWidth()-(400*retinaScale))*.5f,(ofGetHeight()-(400*retinaScale))*.5f), ImGuiCond_Appearing );
ImGui::SetNextWindowSize(ImVec2(400*retinaScale,400*retinaScale), ImGuiCond_Appearing );
if( ImGui::Begin("About Mosaic", &showAboutWindow, ImGuiWindowFlags_NoCollapse ) ){
if(mosaicLogo && mosaicLogo->isAllocated() && mosaicLogoID && mosaicLogo->getWidth()!=0 ){
float ratio = (150.f*retinaScale) / mosaicLogo->getWidth();
ImGui::Image(GetImTextureID(mosaicLogoID), ImVec2(mosaicLogo->getWidth()*ratio, mosaicLogo->getHeight()*ratio));
}
ImGui::Text( "%s", PACKAGE);
ImGui::Text( "Version %s (%s)", VERSION, VERSION_GRAPHIC );
ImGui::Spacing();
ImGui::TextWrapped( DESCRIPTION );
ImGui::TextWrapped( MOSAIC_WWW );
ImGui::TextWrapped( "Developers: %s", MOSAIC_DEVELOPERS );
ImGui::Spacing();
ImGui::Text(" ");
ImGui::Spacing();
if (ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_None)){
if (ImGui::BeginTabItem("Build Info")){
ImGui::TextWrapped("Feel free to include the following information in bug reports.");
bool copy_to_clipboard = ImGui::Button("Copy to clipboard");
ImGui::Spacing();
ImGui::BeginChildFrame(ImGui::GetID("Build Configuration"), ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * (18*retinaScale)), ImGuiWindowFlags_NoMove);
if (copy_to_clipboard){
ImGui::LogToClipboard();
}
#ifdef DEBUG
#define BUILDVARIANT "Debug"
#else
#define BUILDVARIANT "Release"
#endif
ImGui::Text( "%s version %s (%s) (%s build)", PACKAGE, VERSION, VERSION_GRAPHIC , BUILDVARIANT );
ImGui::Separator();
#ifdef _WIN32
ImGui::Text("define: _WIN32");
#endif
#ifdef _WIN64
ImGui::Text("define: _WIN64");
#endif
#ifdef __linux__
ImGui::Text("define: __linux__");
#endif
#ifdef __APPLE__
ImGui::Text("define: __APPLE__");
#endif
#ifdef _MSC_VER
ImGui::Text("define: _MSC_VER=%d", _MSC_VER);
#endif
#ifdef __MINGW32__
ImGui::Text("define: __MINGW32__");
#endif
#ifdef __MINGW64__
ImGui::Text("define: __MINGW64__");
#endif
#ifdef __GNUC__
ImGui::Text("define: __GNUC__=%d", (int)__GNUC__);
#endif
ImGui::Text("define: __cplusplus=%d", (int)__cplusplus);
ImGui::Separator();
ofxVPObjects::factory::objectCategories& objectsMatrix = ofxVPObjects::factory::getCategories();
for(ofxVPObjects::factory::objectCategories::iterator it = objectsMatrix.begin(); it != objectsMatrix.end(); ++it ){
if(it->second.size()<1) continue;
for(auto objIt=it->second.begin(); objIt!=it->second.end(); ++objIt){
ImGui::Text("object/%s: %s", it->first.c_str(), (*objIt).c_str() );
}
}
ImGui::Spacing();
if (copy_to_clipboard){
ImGui::LogFinish();
}
ImGui::EndChildFrame();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Objects")){
ImGui::TextWrapped("This version of Mosaic has been built with the following objects :" );
ImGui::Spacing();
ofxVPObjects::factory::objectCategories& objectsMatrix = ofxVPObjects::factory::getCategories();
if (objectsMatrix.size()>0){
ofxVPObjects::factory::objectCategories& objectsMatrix = ofxVPObjects::factory::getCategories();
for(ofxVPObjects::factory::objectCategories::iterator it = objectsMatrix.begin(); it != objectsMatrix.end(); ++it ){
if (ImGui::TreeNodeEx( it->first.c_str(), ImGuiTreeNodeFlags_DefaultOpen )){
ImGui::Indent(10);
for(auto objIt=it->second.begin(); objIt!=it->second.end(); ++objIt){
ImGui::Text("%s", (*objIt).c_str());
}
ImGui::Unindent(10);
ImGui::TreePop();
}
}
}
else {
ImGui::Text("There are no objects.");
}
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
}
ImGui::End(); // end showAboutWindow
}
// code editor
if(isCodeEditorON){
ImGui::SetNextWindowSize(ImVec2(640*retinaScale,640*retinaScale), ImGuiCond_Appearing);
if( ImGui::Begin(ICON_FA_CODE " Code Editor", &isCodeEditorON, ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoCollapse) ){
isOverCodeEditor = ImGui::IsAnyWindowHovered() || ImGui::IsAnyItemHovered();
if(codeEditors.size() > 0){
auto cpos = codeEditors[editedFilesNames[actualCodeEditor]].GetCursorPosition();
if (ImGui::BeginMenuBar()){
if (ImGui::BeginMenu("File")){
if (ImGui::MenuItem("Save/Reload",ofToString(shortcutFunc+"+R").c_str())){
filesystem::path tempPath(editedFilesPaths[actualCodeEditor].c_str());
ofBuffer buff;
buff.set(codeEditors[editedFilesNames[actualCodeEditor]].GetText());
ofBufferToFile(tempPath,buff,false);
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Edit")){
if (ImGui::MenuItem("Undo", ofToString(shortcutFunc+"+Z").c_str(), nullptr, codeEditors[editedFilesNames[actualCodeEditor]].CanUndo()))