index.html 11.5 KB
Newer Older
Jonathan Wilkes's avatar
Jonathan Wilkes committed
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
<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <input style="display:none;" id="fileDialog" type="file" nwworkingdir multiple />
    <script>
        'use strict';
        var nw = require('nw.gui');
        console.log(nw.App.argv);
        var pdgui = require('./pdgui.js');
        var port_no = nw.App.argv[0]; // fed to us by the Pd process
        var pwd = process.env.PWD;
        pdgui.set_port(port_no);
        pdgui.set_pwd(pwd);
        pdgui.set_pd_window(this);
        pdgui.set_app_quitfn(app_quit);

        console.log("Hello from " + pwd);

        function app_quit () {
            console.log("quitting for reals");
            nw.App.quit();
        }

        var chooser = document.querySelector("#fileDialog");
        chooser.addEventListener("change", function(evt) {
            var file_array = this.value;
            // reset value so that we can open the same file twice
            this.value = null;
            pdgui.menu_open(file_array);
            console.log("tried to open something");
        }, false);



//        prompt("hey", "you");

        // Invoke some functions to create main menus, etc.

        nw.Window.get().on("close", function() {
            pdgui.menu_quit();
// stop-gap to shutdown properly
//            this.close(true);
        });
        console.log(nw.App.argv); 

        document.getElementById("fileDialog").setAttribute("nwworkingdir", pwd);
        document.getElementById("fileDialog").setAttribute("accept",
            Object.keys(pdgui.pd_filetypes).toString());

        nw_create_pd_window_menus();

        pdgui.connect();
        pdgui.init_socket_events();

        // nw context callbacks (mostly just creating/destroying windows)
        pdgui.set_new_window_fn(nw_create_window);
        pdgui.set_close_window_fn(nw_close_window);


        function pdmenu_copy () {
            alert("Please implement pdmenu_copy"); 
        }

        function pdmenu_selectall () {
            alert("Please implement pdmenu_selectall"); 
        }

        function pdmenu_preferences () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_next_win () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_previous_win () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_parent_win () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_console_win () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_audio_on () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_audio_off () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_test_audio () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_load_meter () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_about_pd () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_manual () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_help_browser () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_l2ork_mailinglist () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_pd_mailinglists () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_forums () {
            alert("Please implement pdmenu_preferences"); 
        }

        function pdmenu_irc () {
            alert("Please implement pdmenu_preferences"); 
        }

// Menus for the main Pd window
function nw_create_pd_window_menus () {
    // Window menu
    var windowMenu = new nw.Menu({
        type: 'menubar'
    });

    // File menu
    var fileMenu = new nw.Menu();

    // Add to window menu
    windowMenu.append(new nw.MenuItem({
        label: 'File',
        submenu: fileMenu
    }));

    // File sub-entries
    fileMenu.append(new nw.MenuItem({
        label: 'New',
        click: pdgui.menu_new,
        key: 'n',
        modifiers: "ctrl"
    }));

    fileMenu.append(new nw.MenuItem({
        label: 'Open',
        key: 'o',
        modifiers: "ctrl",
        click: function (){
            var chooser = document.querySelector('#fileDialog');
            chooser.click();
        }
    }));

    if (pdgui.k12_mode == 1) {
        fileMenu.append(new nw.MenuItem({
        label: 'K12 Demos',
        click: pdgui.menu_k12_open_demos
        }));
    }

    fileMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    // Note: this must be different for the main Pd window
    fileMenu.append(new nw.MenuItem({
        label: 'Save',
            click: function () {},
            enabled: false,
        key: 's',
        modifiers: "ctrl"
    }));

    fileMenu.append(new nw.MenuItem({
        label: 'Save as...',
        click: function (){},
        enabled: false,
        key: 'S',
        modifiers: "ctrl"
    }));

    if (pdgui.k12_mode == 0) {
        fileMenu.append(new nw.MenuItem({
            type: 'separator'
        }));
    }

    fileMenu.append(new nw.MenuItem({
        label: 'Message...',
        click: pdgui.menu_send,
        key: 'm',
        modifiers: "ctrl"
    }));

    if (pdgui.k12_mode == 0) {
        fileMenu.append(new nw.MenuItem({
            type: 'separator'
        }));
    }

    // recent files go here

    // anther separator goes here if there are any recent files

    // Note: there's no good reason to have this here
    fileMenu.append(new nw.MenuItem({
        label: 'Close',
        click: function () {},
        enabled: false,
    }));

    // Quit Pd
    fileMenu.append(new nw.MenuItem({
        label: 'Quit',
        click: pdgui.menu_quit,
        key: 'q',
        modifiers: "ctrl"
    }));


    // Edit menu
    var editMenu = new nw.Menu();

    // Add to window menu
    windowMenu.append(new nw.MenuItem({
    label: 'Edit',
    submenu: editMenu
    }));

    // Edit sub-entries
    editMenu.append(new nw.MenuItem({
        label: 'Copy',
        click: pdmenu_copy,
        key: 'c',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Select All',
        click: function () {
            document.selectAllChildren(document);
        },
        key: 'a',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Zoom In',
        click: function () {
            nw.Window.get().zoomLevel += 1;
            pdgui.gui_post("zoom level is " + nw.Window.get().zoomLevel);
        },
        key: '=',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Zoom Out',
        click: function () {
            nw.Window.get().zoomLevel -= 1;
            pdgui.gui_post("zoom level is " + nw.Window.get().zoomLevel);
        },
        key: '-',
        modifiers: "ctrl"
    }));

    editMenu.append(new nw.MenuItem({
        label: 'Preferences...',
        click: pdmenu_preferences,
        key: 'a',
        modifiers: "ctrl"
    }));


    // Windows menu... call it "winman" (i.e., window management) to avoid confusion
    var winmanMenu = new nw.Menu();

    // Add to windows menu
    windowMenu.append(new nw.MenuItem({
    label: 'Windows',
    submenu: winmanMenu
    }));

    // Winman sub-entries
    winmanMenu.append(new nw.MenuItem({
        label: 'Next Window',
        click: pdmenu_next_win,
        key: 'c',
        modifiers: "ctrl"
    }));

    winmanMenu.append(new nw.MenuItem({
        label: 'Previous Window',
        click: pdmenu_previous_win,
        key: 'a',
        modifiers: "ctrl"
    }));

    winmanMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    winmanMenu.append(new nw.MenuItem({
        label: 'Parent Window',
        click: pdmenu_parent_win,
        key: 'a',
        modifiers: "ctrl"
    }));

    winmanMenu.append(new nw.MenuItem({
        label: 'Pd & Console',
        click: pdmenu_console_win,
        key: 'a',
        modifiers: "ctrl"
    }));

    // Media menu
    var mediaMenu = new nw.Menu();

    // Add to window menu
    windowMenu.append(new nw.MenuItem({
    label: 'Media',
    submenu: mediaMenu
    }));

    // Media sub-entries
    mediaMenu.append(new nw.MenuItem({
        label: 'Audio On',
        click: function() {
            pdgui.pdsend("pd dsp 1");
        },
        key: 'c',
        modifiers: "ctrl"
    }));

    mediaMenu.append(new nw.MenuItem({
        label: 'Audio Off',
        click: function() {
            pdgui.pdsend("pd dsp 0");
        },
        key: 'a',
        modifiers: "ctrl"
    }));

    mediaMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    mediaMenu.append(new nw.MenuItem({
        label: 'Test Audio and Midi',
        click: pdmenu_test_audio,
        key: 'a',
        modifiers: "ctrl"
    }));

    mediaMenu.append(new nw.MenuItem({
        label: 'Load Meter',
        click: pdmenu_load_meter,
        key: 'a',
        modifiers: "ctrl"
    }));

    // Help menu
    var helpMenu = new nw.Menu();

    // Add to window menu
    windowMenu.append(new nw.MenuItem({
    label: 'Help',
    submenu: helpMenu
    }));

    // Help sub-entries
    helpMenu.append(new nw.MenuItem({
        label: 'About Pd-L2ork',
        click: pdmenu_about_pd,
        key: 'c',
        modifiers: "ctrl"
    }));

    helpMenu.append(new nw.MenuItem({
        label: 'Manual',
        click: pdmenu_manual,
        key: 'a',
        modifiers: "ctrl"
    }));

    helpMenu.append(new nw.MenuItem({
        label: 'Help Browser',
        click: pdmenu_help_browser,
        key: 'a',
        modifiers: "ctrl"
    }));

    helpMenu.append(new nw.MenuItem({
        type: 'separator'
    }));

    helpMenu.append(new nw.MenuItem({
        label: 'Pd-L2ork Mailing List',
        click: pdmenu_l2ork_mailinglist,
        key: 'a',
        modifiers: "ctrl"
    }));

    helpMenu.append(new nw.MenuItem({
        label: 'Pure Data Mailing Lists',
        click: pdmenu_pd_mailinglists,
        key: 'a',
        modifiers: "ctrl"
    }));

    helpMenu.append(new nw.MenuItem({
        label: 'Forums',
        click: pdmenu_forums,
        key: 'a',
        modifiers: "ctrl"
    }));

    helpMenu.append(new nw.MenuItem({
        label: 'IRC Chat',
        click: pdmenu_irc,
        key: 'a',
        modifiers: "ctrl"
    }));

    // Assign to window
    nw.Window.get().menu = windowMenu;
}

function nw_close_window(window) {
    window.close(true);
}

function nw_create_window(cid, width, height, xpos, ypos, menu_flag, resize, topmost, cnv_color,
    canvas_string, dir, dirty_flag, cargs) {
        // todo: make a separate way to format the title for OSX
    var my_title =  pdgui.format_window_title(canvas_string, dirty_flag, cargs, dir);

    var new_win = nw.Window.open('pdcanvas.html', {
        title: my_title,
        position: "center",
        toolbar: true,
        focus: true,
        width: width,
        height: height,
        x: xpos,
        y: ypos
    });
    return new_win;
}

function canvasNew(args) {
    console.log(args);
}





    </script>
    <input style="display:none;" id="saveDialog" type="file" nwsaveas />

    <pre id="p1" style="white-space: pre-wrap;">Welcome to Pd GUI using Node-Webkit
      <script>document.write(process.versions['node-webkit'])</script><br/></pre> 

    <script>


    </script>
  </body>
</html>