PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PEBLObjects.cpp
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/libs/PEBLObjects.cpp
4// Purpose: Function Library for managing PEBL Objects
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003-2026 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
28
29#include "PEBLObjects.h"
30#include "PEBLEnvironment.h"
31#include "../base/Variant.h"
32#include "../base/PList.h"
33#include "../base/PComplexData.h"
34
35#ifdef PEBL_EMSCRIPTEN
36#include "../base/Evaluator-es.h"
37#include "../devices/PEventLoop-es.h"
38#include <emscripten.h>
39#else
40#include "../base/Evaluator.h"
41#include "../devices/PEventLoop.h"
42#endif
43
44
45
46
47#include "../base/PEBLObject.h"
48#include "../devices/PEyeTracker.h"
49
50#include "../devices/DeviceState.h"
51
52
53
54#include "../objects/PColor.h"
55#include "../objects/PTextBox.h"
56#include "../objects/PDrawObject.h"
57#include "../objects/PCustomObject.h"
58#include "../utility/PError.h"
59#include "../utility/PEBLUtility.h"
60#include "../utility/Defs.h"
61
62#ifdef PEBL_VALIDATOR
63#include "../platforms/validator/PlatformEnvironment.h"
64#include "../platforms/validator/PlatformWindow.h"
65#include "../platforms/validator/PlatformImageBox.h"
66#include "../platforms/validator/PlatformDrawObject.h"
67#include "../platforms/validator/PlatformLabel.h"
68#include "../platforms/validator/PlatformFont.h"
69#include "../platforms/validator/PlatformEventQueue.h"
70#include "../platforms/validator/PlatformTextBox.h"
71#include "../platforms/validator/PlatformCanvas.h"
72#include "../platforms/validator/PlatformAudioOut.h"
73#else
74#include "../platforms/sdl/PlatformEnvironment.h"
75#include "../platforms/sdl/PlatformWindow.h"
76#include "../platforms/sdl/PlatformImageBox.h"
77#include "../platforms/sdl/PlatformDrawObject.h"
78#include "../platforms/sdl/PlatformLabel.h"
79#include "../platforms/sdl/PlatformFont.h"
80#include "../platforms/sdl/PlatformEventQueue.h"
81#include "../platforms/sdl/PlatformTextBox.h"
82#include "../platforms/sdl/PlatformCanvas.h"
83#include "../platforms/sdl/PlatformAudioIn.h"
84
85#ifdef PEBL_MOVIES
86#include "../platforms/sdl/PlatformMovie.h"
87#endif
88#endif
89
90
91
92#include "PEBLList.h"
93
94#include <string>
95using std::string;
96using std::cout;
97using std::endl;
98
99namespace PEBLObjects
100{
101}
102
103//Initiate static data
106
107
109// PEBLObjects::myEnv, creating a new Environment for displaying
112
114 bool windowed,bool resizeable,bool unicode)
115{
116
117 myEnv = new PlatformEnvironment(mode, depth, windowed,resizeable,unicode);
118 myEnv->Initialize();
119 //Initialize the event queue.
121
122}
123
124
125
129{
130
131 //Get default window size:
132 Variant width = myEval->gGlobalVariableMap.RetrieveValue("gVideoWidth");
133 Variant height= myEval->gGlobalVariableMap.RetrieveValue("gVideoHeight");
134
135
136
137 //If there is no argument, make the black grey.
138 //If there is an argument, it should be the name of a color
139 Variant color;
140 PColor * pcolor = NULL;
141 PList * plist = NULL;
142
143 if(v.IsStackSignal())
144 {
145 pcolor = new PColor("black");
146 }
147 else
148 {
149
150 plist = v.GetComplexData()->GetList();
151 color = plist->First();
152
153 if(color.IsComplexData())
154 {
155 if((color.GetComplexData())->IsColor())
156 {
157 pcolor = new PColor(*((PColor*)(color.GetComplexData()->GetObject().get())));
158
159 }
160 else
161 {
162
163 PError::SignalFatalError("Wanted color or colorname as first argument of MakeWindow()");
164 }
165
166 } else {
167
168 PError::AssertType(color, PEAT_STRING,"Argument error in [MakeWindow(<color>)]: ");
169 pcolor = new PColor(color.GetString());
170 }
171 //now, get the width/height if they are there.
172
173 if(plist->Length()>=2)
174 {
175 width = plist->Nth(2);
176 }
177
178 if(plist->Length()>=3)
179 {
180 height = plist->Nth(3);
181 }
182 }
183
184
185
186
187 //Create a new window, and reference it in a counted pointer.
188 PlatformWindow * myWindow = new PlatformWindow(myEnv);
189 myWindow->SetBackgroundColor(*pcolor);
192 bool windowed = myEnv->GetWindowed();
193 bool resizeable = myEnv->GetResizeable();
194
195 myWindow->Initialize(mode, depth, windowed,resizeable,
196 (unsigned int)(int)(width),
197 (unsigned int)(int)(height));
198
199 //Add the window to the environment
200 myEnv->AddWindow(myWindow);
201
203
204 PComplexData * pcd = new PComplexData(tmp2);
205
206 Variant tmp = Variant(pcd);
207
208#ifdef PEBL_EMSCRIPTEN
209 // Debug: Use EM_ASM to ensure output isn't optimized away
210 EM_ASM({
211 console.log("=== C++ MakeWindow() CALLED ===");
212 });
213
214 std::string tmpStr = tmp.GetString();
215 EM_ASM({
216 console.log("C++ MakeWindow: Variant as string: [" + UTF8ToString($0) + "]");
217 }, tmpStr.c_str());
218
219 EM_ASM({
220 console.log("C++ MakeWindow: tmp.IsComplexData() = " + $0);
221 }, tmp.IsComplexData());
222#endif
223
224 delete pcd;
225 delete pcolor;
226 pcd=NULL;
227 //cout << "Deleting PCD Window in PEBLOBjects::MakeWindow\n";
228 return tmp;
229}
230
231
232
234{
235
236 PList * plist = v.GetComplexData()->GetList();
237
238 Variant v2 = plist->First(); //plist->PopFront();
239 PError::AssertType(v2, PEAT_WINDOW, "Argument error in first argument of function [ResizeWindow(<window>,<w>,<h>)]: ");
240 PlatformWindow * myWindow = dynamic_cast<PlatformWindow*>(v2.GetComplexData()->GetObject().get());
241
242 Variant w = plist->Nth(2);
243
244 Variant h = plist->Nth(3);
245 PError::AssertType(w, PEAT_NUMBER, "Argument error in second argument of function [ResizeWindow(<window>,<w>,<h>)]: ");
246 PError::AssertType(h, PEAT_NUMBER, "Argument error in third argument of function [ResizeWindow(<window>,<w>,<h>)]: ");
247
248
249 myWindow->Resize(w,h);
250 return Variant(1);
251}
252
253
254
256{
257 //v[1] should be have a filename in it.
258 PList * plist = v.GetComplexData()->GetList();
259 Variant name = plist->First();
260 PError::AssertType(name, PEAT_STRING, "Argument error in function [MakeImage(<filename>)]: ");
261 PlatformImageBox * myImageBox = new PlatformImageBox();
262
263 myImageBox->LoadImage(name);
264
265
267 PComplexData * pcd = new PComplexData(tmp2);
268 Variant tmp = Variant(pcd);
269
270 delete pcd;
271 pcd=NULL;
272 return tmp;
273}
274
275
276
278{
279 //v[1] should have text in it,
280 //v[2] should have a font in it.
281
282 PList * plist = v.GetComplexData()->GetList();
283
284
285 //Get the text
286 PError::AssertType(plist->First(), PEAT_STRING, "Argument error in first parameter of function [MakeLabel(<text>, <font>)]: ");
287 std::string text = (plist->First()); //plist->PopFront();
288
289 //Get the font
290 Variant v2 = plist->Nth(2);// plist->PopFront();
291 PError::AssertType(v2, PEAT_FONT, "Argument error in second parameter of function [MakeLabel(<text>, <font>)]: ");
292
294
295
296
297 //Create the 'label'
298 PlatformLabel * tmpLabel = new PlatformLabel(text,tmpFont);
299 //Place it by default at 0,0
300
301 tmpLabel->SetPosition(0,0);
302
304
305
306 //Return a variant containing the label.
307 PComplexData * pcd = new PComplexData(myLabel);
308
309 Variant tmp = Variant(pcd);
310 delete pcd;
311 pcd=NULL;
312 return tmp;
313
314}
315
316
318{
319 //v[1] should have text in it,
320 //v[2] should have a font in it.
321 //v[3] should have a width in it (in pixels)
322 //v[4] should have a height in it (in pixels)
323
324 PList * plist = v.GetComplexData()->GetList();
325 PError::AssertType(plist->First(), PEAT_STRING,"Argument error in first parameter of function [MakeTextBox(<text>,<font>,<width>,<height>)]: ");
326
327 //Get the text
328 string text = (plist->First()).GetString(); //plist->PopFront();
329
330 //Get the font
331 Variant v2 = plist->Nth(2);// plist->PopFront();
332 PError::AssertType(v2, PEAT_FONT, "Argument error in second parameter of function [MakeTextBox(<text>,<font>,<width>,<height>)]: ");
333
335
336
337 //Get the width
338 PError::AssertType(plist->Nth(3), PEAT_NUMBER,"Argument error in third parameter of function [MakeTextBox(<text>,<font>,<width>,<height>)]: ");
339 int width = plist->Nth(3);// plist->PopFront();
340
341 //Get the height
342 PError::AssertType(plist->Nth(4), PEAT_NUMBER,"Argument error in fourth parameter of function [MakeTextBox(<text>,<font>,<width>,<height>)]: ");
343
344 int height = plist->Nth(4);// plist->PopFront();
345
346 //Create the text box
347 PlatformTextBox * tmptb = new PlatformTextBox(text, myFont,width,height);
348
349
350 //Place it by default at 0,0
351 tmptb->SetPosition(0,0);
352
353
354
356
357 if((lang=="HE") | (lang == "FA") | (lang == "AR"))
358 {
359 tmptb->SetProperty("JUSTIFY","RIGHT");
360 }
362
363 //Return a variant containing the label.
364 PComplexData * pcd = new PComplexData(myTextBox);
365
366 Variant tmp = Variant(pcd);
367 delete pcd;
368 pcd=NULL;
369 return tmp;
370
371
372}
373
374
376{
377
378 //
379 // v[1] should be X, v[2] shoud be Y
380 // v[3] should be the color (optional),
381 PList * plist = v.GetComplexData()->GetList();
382
383 PError::AssertType(plist->First(), PEAT_NUMBER, "Argument error in first parameter of function [MakeCanvas(<x>, <y>, <color>)]: ");
384 int width = plist->First();// plist->PopFront();
385
386 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [MakeCanvas(<x>, <y>, <color>)]: ");
387 int height = plist->Nth(2);// plist->PopFront();
388
389 PlatformCanvas * pc =NULL;
390 if(plist->Length()>2)
391 {
392 PError::AssertType(plist->Nth(3), PEAT_COLOR, "Argument error in third parameter of function [MakeCanvas(<x>, <y>, <color>)]: ");
393
394 Variant color = plist->Nth(3);// plist->PopFront();
395 pc = new PlatformCanvas(width,height,color);
396
397 }else {
398 pc = new PlatformCanvas(width,height);
399 }
400
402 PComplexData * pcd = new PComplexData(myCanvas);
403
404 Variant tmp = Variant(pcd);
405 delete pcd;
406 pcd=NULL;
407 return tmp;
408}
409
410
411
413{
414 //v[1] should be a color name
415 //Access for rgb and rgba colors should be provided.
416
417
418 PList * plist = v.GetComplexData()->GetList();
419
420 std::string name = plist->First();// plist->PopFront();
421
423 PComplexData * pcd = new PComplexData(myColor);
424 Variant tmp = Variant(pcd);
425 delete pcd;
426 pcd=NULL;
427 return tmp;
428
429}
430
432{
433 //v[1] [2] [3] should be RGB values between 0 and 255
434 PList * plist = v.GetComplexData()->GetList();
435
436 PError::AssertType(plist->First(), PEAT_INTEGER, "Argument error in first parameter of function [MakeColorRGB(<red>, <green>, <blue>)]: ");
437 int red = plist->First();// plist->PopFront();
438
439 PError::AssertType(plist->Nth(2), PEAT_INTEGER, "Argument error in second parameter of function [MakeColorRGB(<red>, <green>, <blue>)]: ");
440 int green = plist->Nth(2);// plist->PopFront();
441
442 PError::AssertType(plist->Nth(3), PEAT_INTEGER, "Argument error in third parameter of function [MakeColorRGB(<red>, <green>, <blue>)]: ");
443 int blue = plist->Nth(3);// plist->PopFront();
444
445 PColor * tmpColor = new PColor(red,green,blue, 255);
447 PComplexData * pcd = new PComplexData(myColor);
448
449
450 Variant tmp = Variant(pcd);
451 delete pcd;
452 pcd=NULL;
453 return tmp;
454
455}
456
457
458
460{
461 //v[1-6] should be have font parameters in it.
462 PList * plist = v.GetComplexData()->GetList();
463
464 //First comes the filename of the font.
465 PError::AssertType(plist->First(), PEAT_STRING, "Argument error in first parameter of function [MakeFont(<filename>, <style>, <size>, <fg>, <bg>, <aa>)]: ");
466 std::string name = plist->First(); //plist->PopFront();
467
468 //Next comes the style, an integerized code for normal, bold, italic, underline.
469 PError::AssertType(plist->Nth(2), PEAT_INTEGER, "Argument error in second parameter of function [MakeFont(<filename>, <style>, <size>, <fg>, <bg>, <aa>)]: ");
470 int style = plist->Nth(2); //plist->PopFront();
471
472 //Next is the point size.
473 PError::AssertType(plist->Nth(3), PEAT_INTEGER, "Argument error in third parameter of function [MakeFont(<filename>, <style>, <size>, <fg>, <bg>, <aa>)]: ");
474 int size = plist->Nth(3);// plist->PopFront();
475
476 //The next parameter should be a PColor--foreground color
477 Variant vfg = plist->Nth(4); //plist->PopFront();
478 PError::AssertType(vfg, PEAT_COLOR, "Argument error in fourth parameter of function [MakeFont(<filename>, <style>, <size>, <fg>, <bg>, <aa>)]: ");
479 PColor fgcolor = *((PColor*)(vfg.GetComplexData()->GetObject().get()));
480
481
482 //The next parameter should be a PColor--background color
483 Variant vbg = plist->Nth(5); //plist->PopFront();
484 PError::AssertType(vbg, PEAT_COLOR, "Argument error in fifth parameter of function [MakeFont(<filename>, <style>, <size>, <fg>, <bg>, <aa>)]: ");
485
486 PColor bgcolor = *((PColor*)(vbg.GetComplexData()->GetObject().get()));
487 //Whether the font should be rendered with anti-aliasing against background.
488
489 PError::AssertType(plist->Nth(6), PEAT_INTEGER, "Argument error in sixth parameter of function [MakeFont(<filename>, <style>, <size>, <fg>, <bg>, <aa>)]: ");
490 bool aa = plist->Nth(6);// plist->PopFront();
491
492 //Make the font and wrap it up in a Variant to return it.
493 PlatformFont * tmpFont = new PlatformFont(name, style, size, fgcolor, bgcolor, aa);
495
496 // Directly pass new PComplexData to Variant constructor - it takes ownership
497 // This avoids double allocation and memory leak
498 return Variant(new PComplexData(myFont));
499
500}
501
502
503
506{
507 //v[1] should have the child widget
508 //v[2] should have the parent widget
509
510 PList * plist = v.GetComplexData()->GetList();
511
512
513 Variant v1 = plist->First(); //plist->PopFront();
514 PError::AssertType(v1, PEAT_WIDGET, "Argument error in first parameter of function [AddObject(<child-widget>, <parent-widget>)]: ");
515
516
517 PlatformWidget * child = dynamic_cast<PlatformWidget*>((v1.GetComplexData())->GetObject().get());
518
519 Variant v2 = plist->Nth(2); //plist->PopFront();
520 PError::AssertType(v2, PEAT_WIDGET, "Argument error in second parameter of function [AddObject(<child-widget>, <parent-widget>)]: ");
521
522 PlatformWidget * parent = dynamic_cast<PlatformWidget*>((v2.GetComplexData())->GetObject().get());
523
524
525 parent->AddSubWidget(child);
526 child->SetProperty("PARENT",v2);
527
528 return Variant(true);
529}
530
531
532
535{
536 //v[1] should have the child widget
537 //v[2] should have the parent widget
538 PList * plist = v.GetComplexData()->GetList();
539 Variant v1 = plist->First();// plist->PopFront();
540 PError::AssertType(v1, PEAT_WIDGET, "Argument error in first parameter of function [RemoveObject(<child-widget>, <parent-widget>)]: ");
541
542
543 PlatformWidget * child = dynamic_cast<PlatformWidget*>(v1.GetComplexData()->GetObject().get());
544
545 Variant v2 = plist->Nth(2);//plist->PopFront();
546 PError::AssertType(v2, PEAT_WIDGET, "Argument error in second parameter of function [RemoveObject(<child-widgett>, <parent-widget>)]: ");
547
548
549 PlatformWidget * parent = dynamic_cast<PlatformWidget*>(v2.GetComplexData()->GetObject().get());
550
551 //Removing subwidgets does not destroy the Variant, so we don't need to
552 // worry about a memory leak here, even though we are using raw pointers.
553 //however,we need to check whether the child is actually a member of the parent,
554 //otherwise things could go bad.
555
556 if(!child | !parent)
557 {
558 return Variant(false);
559 }
560
561 if(! child->IsParent(parent))
562 {
563 PError::SignalFatalError("Trying to remove object from another object that is not its parent\n");
564 }
565
566
567 parent->RemoveSubWidget(child);
568
569 return Variant(true);
570}
571
572
574{
575
576 PList * plist = v.GetComplexData()->GetList();
577
578 Variant v1 = plist->First(); //plist->PopFront();
579 PError::AssertType(v1, PEAT_WIDGET, "Argument error in first parameter of function [SetPoint(<widget>,<x>, <y>, <color>)]: ");
580 PlatformWidget * widget = dynamic_cast<PlatformWidget*>(v1.GetComplexData()->GetObject().get());
581
582
583 int x = plist->Nth(2);// plist->PopFront();
584 PError::AssertType(x, PEAT_NUMBER, "Argument error in second parameter of function [SetPoint(<widget>,<x>, <y>, <color>)]: ");
585
586 int y = plist->Nth(3);// plist->PopFront();
587 PError::AssertType(y, PEAT_NUMBER, "Argument error in third parameter of function [SetPoint(<widget>,<x>, <y>, <color>)]: ");
588
589 Variant color = plist->Nth(4);// plist->PopFront();
590 PError::AssertType(color, PEAT_COLOR, "Argument error in fourth parameter of function [SetPoint(<widget>,<x>, <y>, <color>)]: ");
591
592
593 PColor pcolor = *((PColor*)(color.GetComplexData()->GetObject().get()));
594 widget->SetPoint(x,y,pcolor);
595
596 return Variant(true);
597}
598
600{
601 PList * plist = v.GetComplexData()->GetList();
602
603 Variant v1 = plist->First(); //plist->PopFront();
604 PError::AssertType(v1, PEAT_WIDGET, "Argument error in first parameter of function [GetPixelColor(<widget>,<x>, <y>)]: ");
605 PlatformWidget * widget = dynamic_cast<PlatformWidget*>(v1.GetComplexData()->GetObject().get());
606
607
608 int x = plist->Nth(2);// plist->PopFront();
609 PError::AssertType(x, PEAT_NUMBER, "Argument error in second parameter of function [GetPixelColor(<widget>,<x>, <y>, <color>)]: ");
610
611 int y = plist->Nth(3);// plist->PopFront();
612 PError::AssertType(y, PEAT_NUMBER, "Argument error in third parameter of function [GetPixelColor(<widget>,<x>, <y>)]: ");
613
614 PColor c1 = (widget->GetPixel(x,y));
615
616 PColor * tmpColor = new PColor(c1);
617
619 PComplexData * pcd = new PComplexData(myColor);
620
621 Variant tmp = Variant(pcd);
622 delete pcd;
623 pcd=NULL;
624 return tmp;
625}
626
627//This sets the cursor location (in characters) within a textbox.
629{
630 PList * plist = v.GetComplexData()->GetList();
631
632 PError::AssertType(plist->First(), PEAT_TEXTBOX, "Argument error in first argument of function [SetCursorPosition(<textbox>, <position>)]: ");
633
634
635 counted_ptr<PEBLObjectBase> textbox = plist->First().GetComplexData()->GetObject(); //plist->PopFront();
636
637 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second argument of function [SetCursorPosition(<textbox>, <position>)]: ");
638 Variant v1 = plist->Nth(2);// plist->PopFront();
639
640 (dynamic_cast<PTextBox *>(textbox.get()))->SetCursorPosition(v1.GetInteger());
641
642 return Variant(1);
643}
644
645//This gets the cursor location (in characters) within a textbox.
647{
648 PList * plist = v.GetComplexData()->GetList();
649
650 PError::AssertType(plist->First(), PEAT_TEXTBOX, "Argument error in function [GetCursorPosition(<textbox>)]: ");
651
652 counted_ptr<PEBLObjectBase> textbox = plist->First().GetComplexData()->GetObject(); //plist->PopFront();
653 return Variant((dynamic_cast<PTextBox *>(textbox.get()))->GetCursorPosition());
654}
655
656
657
659{
660
661 PList * plist = v.GetComplexData()->GetList();
662 Variant v0 = plist->First();
663 PError::AssertType(v0,PEAT_WIDGET,"Error in GetParent(<widget>): argument is not a widget");
664
665
666
667 PlatformWidget * obj = dynamic_cast<PlatformWidget*>(v0.GetComplexData()->GetObject().get());
668
669 PWidget * parent = obj->GetParent();
670
671 if(parent)
672 {
674 PComplexData * pcd = new PComplexData(tmp2);
675 Variant tmp = Variant(pcd);
676
677 return tmp;
678 }else{
679
680 return Variant(0);
681 }
682}
683
685{
686 PList * plist = v.GetComplexData()->GetList();
687
688 PError::AssertType(plist->First(), PEAT_TEXTBOX, "Argument error in first argument of function [SetEditable(<textbox>, <boolean>)]: ");
689
690 PlatformTextBox * textbox = dynamic_cast<PlatformTextBox*>(plist->Nth(1).GetComplexData()->GetObject().get()); //plist->PopFront();
691
692 Variant v1 = plist->Nth(2); //plist->PopFront();
693
694 if(bool(v1))
695 {
696 textbox->SetEditable(true);
697 return Variant(true);
698 }
699 else
700 {
701 textbox->SetEditable(false);
702 return Variant(false);
703 }
704
705}
706
707
708
710{
711
712 PList * plist = v.GetComplexData()->GetList();
713
714
715 //This can be used on either a textbox or a label.
716 Variant v1 = plist->First(); //plist->PopFront();
717 PError::AssertType(v1, PEAT_TEXTOBJECT, "Argument error in first argument of function [SetText(<object>, <text>)]: ");
718 //Get the text to change it to.
719 Variant v2 = plist->Nth(2);//First(); plist->PopFront();
720 PError::AssertType(v2, PEAT_STRING, "Argument error in second argument of function [SetText(<object>, <text>)]: ");
721
722
723 //Make the change.
724 if(v1.GetComplexData()->IsLabel() )
725 {
726 PlatformLabel * label = dynamic_cast<PlatformLabel*>(v1.GetComplexData()->GetObject().get());
727 label->SetText(v2.GetString());
728 }
729 else
730 {
731 PlatformTextBox * textbox = dynamic_cast<PlatformTextBox*>(v1.GetComplexData()->GetObject().get());
732 textbox->SetText(v2.GetString());
733
734 }
735
736 return Variant(1);
737}
738
739
741{
742 PList * plist = v.GetComplexData()->GetList();
743
744 PError::AssertType(plist->First(), PEAT_TEXTBOX, "Argument error in function [GetText(<textbox>)]: ");
745
746 PlatformTextBox * textbox = dynamic_cast<PlatformTextBox*>(plist->First().GetComplexData()->GetObject().get());
747 // plist->PopFront();
748
749 return Variant(textbox->GetText());
750}
751
752
754{
755 PList * plist = v.GetComplexData()->GetList();
756
757 PError::AssertType(plist->First(), PEAT_TEXTBOX, "Argument error in function [GetLineBreaks(<textbox>)]: ");
758
759 PlatformTextBox * textbox = dynamic_cast<PlatformTextBox*>(plist->First().GetComplexData()->GetObject().get());
760 return textbox->GetLineBreaks();
761}
762
764{
765
766 PList * plist = v.GetComplexData()->GetList();
767
768 //This can be used on either a textbox or a label.
769 Variant v1 = plist->First();// plist->PopFront();
770 PError::AssertType(v1, PEAT_TEXTOBJECT, "Argument error in first argument of function [SetFont(<object>, <font>)]: ");
771 //Get the text to change it to.
772 Variant v2 = plist->Nth(2);//First(); plist->PopFront();
773 PError::AssertType(v2, PEAT_FONT, "Argument error in second argument of function [SetFont(<object>, <font>)]: ");
774
775
776 //Make the change.
777 if(v1.GetComplexData()->IsLabel() )
778 {
779 PlatformLabel * label = dynamic_cast<PlatformLabel*>(v1.GetComplexData()->GetObject().get());
780
782 label->SetFont(tmpFont);
783 }
784 else
785 {
786 PlatformTextBox * textbox =dynamic_cast<PlatformTextBox*>(v1.GetComplexData()->GetObject().get());
788 textbox->SetFont(tmpFont);
789 }
790
791 return Variant(1);
792}
793
795{
796 //v[1] could be a widget, or an PEBLObject in general.
797 PList * plist = v.GetComplexData()->GetList();
798 Variant v1 = plist->First();// plist->PopFront();
799 //This should also work for PEBLObjectBase things.
800 //It should also work for devices and the like;
801 //it probably does not currently do so.
802
803 PError::AssertType(v1, PEAT_OBJECT, "Argument error in function [PrintProperties(<object>)]: ");
804
805 //PlatformWidget * widget = dynamic_cast<PlatformWidget*>(v1.GetComplexData()->GetObject().get());
806 PEBLObjectBase* obj = dynamic_cast<PEBLObjectBase*>(v1.GetComplexData()->GetObject().get());
807 obj->PrintProperties(std::cout);
808
809 return Variant(true);
810}
811
812
814{
815 //v[1] could be a widget, or an PEBLObject in general.
816 PList * plist = v.GetComplexData()->GetList();
817 Variant v1 = plist->First();// plist->PopFront();
818 //This should also work for PEBLObjectBase things.
819 //It should also work for devices and the like;
820 //it probably does not currently do so.
821
822 PError::AssertType(v1, PEAT_OBJECT, "Argument error in function [GetPropertyList(<object>)]: ");
823
824 //PlatformWidget * widget = dynamic_cast<PlatformWidget*>(v1.GetComplexData()->GetObject().get());
825 PEBLObjectBase* obj = dynamic_cast<PEBLObjectBase*>(v1.GetComplexData()->GetObject().get());
826
827 return obj->GetPropertyList();
828}
829
830
832{
833
834
835 PList * plist = v.GetComplexData()->GetList();
836 Variant v1 = plist->First();
837 PError::AssertType(v1, PEAT_OBJECT, "Argument error in first parameter of function [SetProperty(<object>,<property>,<value>)]: ");
838
839
840 Variant v2 = plist->Nth(2);
841 PError::AssertType(v2, PEAT_STRING, "Argument error in second parameter of function [SetProperty(<object>,<property>,<value>)]: ");
842
843
844
845
846 Variant v3 = plist->Nth(3);
847 //No need to check v3 for type.
848
850
851 return Variant(true);
852}
853
854
856{
857 PList * plist = v.GetComplexData()->GetList();
858
859 //v[1] should be a list
860 Variant v1 = plist->First(); //plist->PopFront();
861 PError::AssertType(v1, PEAT_OBJECT, "Argument error in first parameter of function [GetProperty(<object>, <property>)]: ");
862
863
864 Variant prop =PEBLUtility::ToUpper( plist->Nth(2));
865
866 //v[2] should be a string
867 PError::AssertType(prop, PEAT_STRING, "Argument error in second parameter of function [Nth(<object>, <property>)]: ");
868 return v1.GetComplexData()->GetProperty(prop);
869
870}
871
872
874{
875
876
877 PList * plist = v.GetComplexData()->GetList();
878
879
880 //v[1] should be a list
881 Variant v1 = plist->First(); //plist->PopFront();
882 PError::AssertType(v1, PEAT_OBJECT, "Argument error in first parameter of function [PropertyExists(<object>, <property>)]: ");
883
884
885 Variant prop =PEBLUtility::ToUpper( plist->Nth(2));
886
887
888 //v[2] should be a string
889 PError::AssertType(prop, PEAT_STRING, "Argument error in second parameter of function [PropertyExists(<object>, <property>)]: ");
890
891 return v1.GetComplexData()->PropertyExists(prop);
892
893}
894
895
896
898{
899
900 //v[1] should have the widget
901 PList * plist = v.GetComplexData()->GetList();
902
903
904 Variant v1 = plist->First(); //plist->PopFront();
905 PError::AssertType(v1, PEAT_WIDGET, "Argument error in function [Show(<widget>)]: ");
906
907
908 PlatformWidget * widget = dynamic_cast<PlatformWidget*>(v1.GetComplexData()->GetObject().get());
909
910 widget->Show();
911
912 return Variant(true);
913}
914
915
916
918{
919
920 //v[1] should have the widget
921 PList * plist = v.GetComplexData()->GetList();
922 Variant v1 = plist->First();// plist->PopFront();
923 PError::AssertType(v1, PEAT_WIDGET, "Argument error in function [Hide(<widget>)]: ");
924 PlatformWidget * widget = dynamic_cast<PlatformWidget*>(v1.GetComplexData()->GetObject().get());
925
926 widget->Hide();
927
928 return Variant(true);
929}
930
931
932
933
934
935
938{
939 //v[1] should have the object. If it is null,
940 //redraw the entire environment.
941
942 if(v.IsStackSignal())
943 {
944 myEnv->Draw();
945 }
946 else
947 {
948
949 PList * plist = v.GetComplexData()->GetList();
950
951 Variant v2 = plist->First(); //plist->PopFront();
952 PError::AssertType(v2, PEAT_WIDGET, "Argument error in function [Draw(<widget>)]: ");
953
954 PlatformWidget * myWidget = dynamic_cast<PlatformWidget*>(v2.GetComplexData()->GetObject().get());
955 myWidget->Draw();
956 }
957 return Variant(true);
958}
959
960
965{
966 PList * plist = v.GetComplexData()->GetList();
967
968 Variant v1 = plist->First(); //plist->PopFront();
969 PError::AssertType(v1, PEAT_WIDGET, "Argument error in first parameter of function [DrawFor(<widndow>, <count>)]: ");
970
971 PlatformWindow * window = dynamic_cast<PlatformWindow*>(v1.GetComplexData()->GetObject().get());
972 PError::AssertType(plist->Nth(2), PEAT_INTEGER, "Argument error in second parameter of function [DrawFor(<window>, <count>)]: ");
973
974 int count =plist->Nth(2);
975
976 long unsigned int time = window->DrawFor(count);
977
978 return Variant(time);
979
980}
981
982
988{
989 //v[1] should have the object, v[2] should be X, v[3] shoud be Y
990 PList * plist = v.GetComplexData()->GetList();
991
992 Variant v1 = plist->First(); //plist->PopFront();
993 PError::AssertType(v1, PEAT_WIDGET, "Argument error in first parameter of function [Move(<widget>,<x>, <y>)]: ");
994
995 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [Move(<widget>,<x>, <y>)]: ");
996 int x = plist->Nth(2); //plist->PopFront();
997
998 PError::AssertType(plist->Nth(3), PEAT_NUMBER, "Argument error in third parameter of function [Move(<widget>,<x>, <y>)]: ");
999 int y = plist->Nth(3); //plist->PopFront();
1000
1001
1002
1003 if(v1.GetComplexData()->IsThickLine() )
1004 {
1005
1006 PlatformThickLine * tl = dynamic_cast<PlatformThickLine*>(v1.GetComplexData()->GetObject().get());
1007 tl->SetPosition(x,y);
1008 }
1009 else
1010 {
1011 //This uses the widget setposition, rather than the child classes overridden version.
1012 PWidget * widget = dynamic_cast<PWidget*>(v1.GetComplexData()->GetObject().get());
1013
1014
1015 widget->SetPosition(x , y);
1016 }
1017
1018 return Variant(true);
1019}
1020
1021
1023{
1024
1025 //v[1] should have the object
1026 PList * plist = v.GetComplexData()->GetList();
1027
1028 Variant v1 = plist->First(); //plist->PopFront();
1029 PError::AssertType(v1, PEAT_WIDGET, "Argument error in GetSize(<widget>). ");
1030
1031
1032 PWidget * widget = dynamic_cast<PWidget*>(v1.GetComplexData()->GetObject().get());
1033
1034 Variant width = widget->GetWidth();
1035 Variant height = widget->GetHeight();
1036
1037 PList * newlist = new PList();
1038
1039 newlist->PushBack(height);
1040 newlist->PushBack(width);
1041
1043 PComplexData * pcd = new PComplexData(newlist2);
1044 Variant tmp = Variant(pcd);
1045 delete pcd;
1046 pcd=NULL;
1047 return tmp;
1048}
1049
1050
1051
1055{
1056 //v[1] should have the filename
1057 PList * plist = v.GetComplexData()->GetList();
1058
1059 Variant v1 = plist->First();// plist->PopFront();
1060 PError::AssertType(v1, PEAT_STRING, "Argument error in function [LoadSound(<filename>)]: ");
1061
1062 PlatformAudioOut * myAudio = new PlatformAudioOut();
1063 myAudio->LoadSoundFile(v1);
1064 // myAudio->Initialize();
1065
1067 PComplexData * pcd = new PComplexData(audio2);
1068 Variant tmp = Variant(pcd);
1069 delete pcd;
1070 pcd=NULL;
1071 return tmp;
1072}
1073
1074
1075
1076
1077//This plays a sound object, returning (almost) immediately, allowing
1078//the sound to play in the background. If you want the function to only return
1079//after the sound playing is complete, use PlayForeground();
1081{
1082 //v[1] should have the PlatformAudioOut object
1083 PList * plist = v.GetComplexData()->GetList();
1084
1085 Variant v1 = plist->First();// plist->PopFront();
1086 PError::AssertType(v1, PEAT_AUDIOOUT, "Argument error in function PlayBackground(<audio-stream>)]: ");
1087
1088 PlatformAudioOut * myAudio = dynamic_cast<PlatformAudioOut*>(v1.GetComplexData()->GetObject().get());
1089 myAudio->Play();
1090 return Variant(true);
1091}
1092
1094{
1095 //v[1] should have the PlatformAudioOut object
1096 PList * plist = v.GetComplexData()->GetList();
1097
1098
1099 Variant v1 = plist->First();// plist->PopFront();
1100
1101 PError::AssertType(v1, PEAT_AUDIOOUT, "Argument error in function PlayForeground(<audio-stream>)]: ");
1102 PlatformAudioOut * myAudio = dynamic_cast<PlatformAudioOut*>(v1.GetComplexData()->GetObject().get());
1103 myAudio->PlayForeground();
1104 return Variant(true);
1105}
1106
1107
1109{
1110 //v[1] should have the PlatformAudioOut object.
1111 PList * plist = v.GetComplexData()->GetList();
1112
1113 Variant v1 = plist->First(); //plist->PopFront();
1114
1115 PError::AssertType(v1, PEAT_AUDIOOUT, "Argument error in function Stop(<audio-stream>)]: ");
1116
1117 PlatformAudioOut * myAudio = dynamic_cast<PlatformAudioOut*>(v1.GetComplexData()->GetObject().get());
1118
1119 myAudio->Stop();
1120 return Variant(true);
1121}
1122
1123
1125{
1126
1127 //v[1] should have the PlatformAudioOut object.
1128 PList * plist = v.GetComplexData()->GetList();
1129 Variant v1 = plist->First(); //plist->PopFront();
1130
1131 PError::AssertType(v1, PEAT_AUDIOOUT, "Argument error in function SetPanning(<audio-stream>,<left>,<right>)]: ");
1132
1133 PlatformAudioOut * myAudio = dynamic_cast<PlatformAudioOut*>(v1.GetComplexData()->GetObject().get());
1134
1135
1136#ifdef PEBL_MIXER
1137
1138 Variant left = (plist->Nth(2));
1139 Variant right = (plist->Nth(3));
1140
1141 PError::AssertType(left,PEAT_NUMBER,"In SetPanning, <left> must be a number between 0 and 1");
1142 PError::AssertType(right,PEAT_NUMBER,"In SetPanning, <right> must be a number between 0 and 1");
1143
1144 myAudio->SetPanning((pDouble)(left),
1145 (pDouble)(right));
1146#endif
1147
1148 return Variant(true);
1149
1150}
1151
1152
1154{
1155 //v[1] should have the PlatformAudioOut object.
1156 PList * plist = v.GetComplexData()->GetList();
1157 Variant v1 = plist->First(); //plist->PopFront();
1158
1159 PError::AssertType(v1, PEAT_AUDIOOUT, "Argument error in function SetPlayRepeats(<audio-stream>,<repeats>)]: ");
1160
1161 PlatformAudioOut * myAudio = dynamic_cast<PlatformAudioOut*>(v1.GetComplexData()->GetObject().get());
1162
1163
1164 Variant repeats = (plist->Nth(2));
1165
1166
1167 PError::AssertType(repeats,PEAT_INTEGER,"In SetPlayRepeats, <times> must be an integer");
1168#ifdef PEBL_MIXER
1169 myAudio->SetRepeats(repeats);
1170#endif
1171 return Variant(true);
1172
1173}
1174
1175
1177{
1178
1179 //v[1] should have the filename
1180 PList * plist = v.GetComplexData()->GetList();
1181
1182
1183 Variant v1 = plist->First(); //plist->PopFront();
1184 PError::AssertType(v1, PEAT_NUMBER, "Argument error in first parameter of function [MakeSineWave(<freq>,<length>,<amplitude>)]: ");
1185
1186 Variant v2 = plist->Nth(2); //plist->PopFront();
1187 PError::AssertType(v2, PEAT_INTEGER, "Argument error in second parameter of function [MakeSineWave(<freq>,<length>,<amplitude>)]: ");
1188
1189 Variant v3 = plist->Nth(3);// plist->PopFront();
1190 PError::AssertType(v3, PEAT_NUMBER, "Argument error in third parameter of function [MakeSineWave(<freq>,<length>,<amplitude>)]: ");
1191
1192 if((((pDouble)v3>1.0 )| ((pDouble)v3<-1.0)))
1193 {
1194 PError::SignalWarning("amplitude in MakeSineWave(<freq>,<length>,<amplitude> will produce clipping if greater than 1.0");
1195 }
1196
1197 PlatformAudioOut * myAudio = new PlatformAudioOut();
1198 myAudio->CreateSineWave((pDouble)v1,(int)v2, (pDouble)v3);
1199 myAudio->Initialize();
1200
1202 PComplexData * pcd = new PComplexData(audio2);
1203 Variant tmp = Variant(pcd);
1204 delete pcd;
1205 pcd=NULL;
1206 return tmp;
1207
1208}
1209
1210
1212{
1213
1214
1215#ifdef PEBL_AUDIOIN
1216 //
1217 PList * plist = v.GetComplexData()->GetList();
1218
1219
1220 Variant v1 = plist->First(); //plist->PopFront();
1221 PError::AssertType(v1, PEAT_NUMBER, "Argument error in first parameter of function [MakeAudioInputBuffer(<duration>)]: ");
1222
1223
1224 PlatformAudioIn * myAudio = new PlatformAudioIn();
1225 myAudio->CreateBuffer(v1);
1226
1227 counted_ptr<AudioInfo> tmp = myAudio->ReleaseAudioOutBuffer();
1228 delete myAudio;
1229
1230 //Variant out = myAudio->VoiceKey(v,(pDouble)v1,(int)v2);
1231 PlatformAudioOut * myOut = new PlatformAudioOut();
1232 myOut->LoadSoundFromData((tmp->audio),tmp->audiolen,&(tmp->spec),tmp->recordpos);
1233 myOut->Initialize();
1234
1236 PComplexData * pcd = new PComplexData(audio2);
1237 Variant tmpv = Variant(pcd);
1238 // delete pcd;
1239 pcd=NULL;
1240 return tmpv;
1241#else
1242 PError::SignalFatalError("Audio Input not available on this version of PEBL.");
1243 return false;
1244#endif
1245
1246}
1247
1248
1250{
1251
1252
1253 PList * plist = v.GetComplexData()->GetList();
1254 Variant v1 = plist->First();// plist->PopFront();
1255 PError::AssertType(v1, PEAT_STRING, "Argument error in first parameter of function [SaveAudioToWaveFile(<filename>,<audio-buffer>)]: ");
1256
1257
1258 Variant v2 = plist->Nth(2);// plist->PopFront();
1259 PError::AssertType(v2, PEAT_AUDIOOUT, "Argument error second parameter of function [SaveAudioToWaveFile(<filename>,<audio-buffer>)]: ");
1260
1261 PlatformAudioOut * myAudio = dynamic_cast<PlatformAudioOut*>(v2.GetComplexData()->GetObject().get());
1262 myAudio->SaveBufferToWave(v1);
1263 return Variant(true);
1264
1265
1266}
1267
1268
1269
1270
1271
1273{
1274#ifdef PEBL_AUDIOIN
1275
1276 //
1277 PList * plist = v.GetComplexData()->GetList();
1278
1279
1280 Variant v1 = plist->First();// plist->PopFront();
1281// PError::AssertType(v1, PEAT_NUMBER, "Argument error in first parameter of function [MakeSineWave(<freq>,<length>,<amplitude>)]: ");
1282
1283 Variant v2 = plist->Nth(2); //plist->PopFront();
1284// PError::AssertType(v2, PEAT_INTEGER, "Argument error in second parameter of function [MakeSineWave(<freq>,<length>,<amplitude>)]: ");
1285
1286 Variant v3 = plist->Nth(3); //plist->PopFront();
1287// PError::AssertType(v3, PEAT_NUMBER, "Argument error in third parameter of function [MakeSineWave(<freq>,<length>,<amplitude>)]: ");
1288
1289// if((((pDouble)v3>1.0 )| ((pDouble)v3<-1.0)))
1290// {
1291// PError::SignalWarning("amplitude in MakeSineWave(<freq>,<length>,<amplitude> will produce clipping if greater than 1.0");
1292// }
1293
1294 //v1 should be a audiout object, which has our buffer.
1295
1296 PlatformAudioOut * po = dynamic_cast<PlatformAudioOut*>(v1.GetComplexData()->GetObject().get());
1298
1299 if(!tmp.get()) {
1300 PError::SignalFatalError("GetVocalResponseTime: Failed to get audio info from buffer");
1301 return Variant(false);
1302 }
1303
1304 PlatformAudioIn * myAudio = new PlatformAudioIn();
1305 myAudio->UseBuffer(tmp); // Pass counted_ptr to UseBuffer (increments reference count)
1306 myAudio->Initialize(1);
1307
1308 Variant out = myAudio->VoiceKey((pDouble)v2,(int)v3);
1309
1310 // Update the PlatformAudioOut's recorded position from the shared AudioInfo
1311 // This is critical for SaveAudioToWaveFile() to save the correct amount of data
1312 po->SetRecordPos(tmp->recordpos);
1313
1314 delete myAudio; // Clean up PlatformAudioIn (AudioInfo is reference counted)
1315
1316 return out;
1317
1318#else
1319 PError::SignalFatalError("Audio Input not available on this version of PEBL.");
1320 return false;
1321#endif
1322
1323}
1324
1326{
1327#ifdef PEBL_AUDIOIN
1328 PList * plist = v.GetComplexData()->GetList();
1329
1330 Variant v1 = plist->First();
1331 PError::AssertType(v1, PEAT_AUDIOOUT, "Argument error in function [RecordToBuffer(<audio-buffer>, [<duration-ms>])]: ");
1332
1333 // v1 should be an audioout object, which has our buffer
1334 PlatformAudioOut * po = dynamic_cast<PlatformAudioOut*>(v1.GetComplexData()->GetObject().get());
1336
1337 if(!tmp.get()) {
1338 PError::SignalFatalError("RecordToBuffer: Failed to get audio info from buffer");
1339 return Variant(false);
1340 }
1341
1342 std::cout << "====================================\n";
1343 std::cout << "RecordToBuffer() Debug Info:\n";
1344 std::cout << "Buffer address: " << (void*)tmp->audio << "\n";
1345 std::cout << "Buffer size: " << tmp->audiolen << " bytes\n";
1346 std::cout << "Sample rate: " << tmp->spec.freq << " Hz\n";
1347 std::cout << "Bytes per sample: " << tmp->bytesPerSample << "\n";
1348
1349 // CRITICAL: Reset recordpos to 0 before recording!
1350 tmp->recordpos = 0;
1351
1352 // Create audio input device and attach the buffer
1353 PlatformAudioIn * myAudio = new PlatformAudioIn();
1354 myAudio->UseBuffer(tmp); // Pass counted_ptr to UseBuffer (increments reference count)
1355 myAudio->Initialize(1); // Type 1 = fill callback
1356
1357 // Start recording
1358 myAudio->RecordToBuffer();
1359
1360 // Check if optional duration parameter was provided
1361 unsigned int durationMs;
1362 if(plist->Length() >= 2) {
1363 // Use provided duration
1364 Variant v2 = plist->Nth(2);
1365 PError::AssertType(v2, PEAT_NUMBER, "Argument error in second parameter of function [RecordToBuffer(<audio-buffer>, [<duration-ms>])]: ");
1366 durationMs = (unsigned int)(int)v2;
1367 std::cout << "Using specified duration: " << durationMs << " ms\n";
1368 } else {
1369 // Calculate duration based on buffer size and sample rate
1370 // audiolen is in bytes, bytesPerSample tells us bytes per sample
1371 // So total samples = audiolen / bytesPerSample
1372 // Time in ms = (samples / sampleRate) * 1000
1373 unsigned int totalSamples = tmp->audiolen / tmp->bytesPerSample;
1374 unsigned int sampleRate = tmp->spec.freq;
1375 durationMs = (totalSamples * 1000) / sampleRate;
1376 std::cout << "Using buffer-based duration: " << durationMs << " ms\n";
1377 }
1378
1379 std::cout << "Total buffer samples: " << (tmp->audiolen / tmp->bytesPerSample) << "\n";
1380 std::cout << "Recording for: " << durationMs << " ms\n";
1381 std::cout << "Recording started...\n";
1382
1383 // Wait for the specified/calculated duration
1384 PEBLEnvironment::myTimer.Sleep(durationMs);
1385
1386 // Pause recording (device remains open until myAudio is deleted)
1387 myAudio->PauseAudioMonitor();
1388
1389 std::cout << "Recording paused.\n";
1390 std::cout << "Buffer recordpos: " << tmp->recordpos << "\n";
1391
1392 // Check if buffer actually contains data
1393 int nonZeroCount = 0;
1394 for(unsigned int i = 0; i < tmp->recordpos && i < 1000; i++) {
1395 if(tmp->audio[i] != 0) nonZeroCount++;
1396 }
1397 std::cout << "First 1000 bytes: " << nonZeroCount << " non-zero values\n";
1398
1399 // Print first few samples as Sint16
1400 Sint16* samples = (Sint16*)tmp->audio;
1401 std::cout << "First 10 samples: ";
1402 for(int i = 0; i < 10; i++) {
1403 std::cout << samples[i] << " ";
1404 }
1405 std::cout << "\n";
1406
1407 // CRITICAL: Update the PlatformAudioOut object with the actual recorded size
1408 // so that SaveBufferToWave() will save the correct amount
1409 po->SetRecordPos(tmp->recordpos);
1410
1411 std::cout << "====================================\n";
1412
1413 delete myAudio; // Clean up PlatformAudioIn (AudioInfo is reference counted)
1414
1415 return Variant(true);
1416
1417#else
1418 PError::SignalFatalError("Audio Input not available on this version of PEBL.");
1419 return Variant(false);
1420#endif
1421}
1422
1423
1424// Start audio monitoring in ring buffer mode for real-time calibration/visualization
1425// Returns an audio monitor object that can be used with GetAudioStats
1427{
1428#ifdef PEBL_AUDIOIN
1429 PList * plist = v.GetComplexData()->GetList();
1430 Variant v1 = plist->First();
1431 PError::AssertType(v1, PEAT_NUMBER, "Argument error in function [StartAudioMonitor(<buffer-size-ms>)]: ");
1432
1433 int bufferSizeMs = (int)v1;
1434
1435 // Create audio input device with ring buffer
1436 PlatformAudioIn * myAudio = new PlatformAudioIn();
1437 myAudio->CreateBuffer(bufferSizeMs);
1438 myAudio->Initialize(2); // Type 2 = ring buffer callback (AudioInCallbackLoop)
1439 myAudio->RecordToBuffer(); // Start recording
1440
1441 std::cout << "Audio monitor started with " << bufferSizeMs << "ms ring buffer\n";
1442
1443 // Wrap in counted_ptr and return as PEBL object
1445 PComplexData * pcd = new PComplexData(audio2);
1446 Variant tmp = Variant(pcd);
1447 delete pcd;
1448 pcd=NULL;
1449 return tmp;
1450
1451#else
1452 PError::SignalFatalError("Audio Input not available on this version of PEBL.");
1453 return Variant(false);
1454#endif
1455}
1456
1457
1458// Stop audio monitoring
1460{
1461#ifdef PEBL_AUDIOIN
1462 PList * plist = v.GetComplexData()->GetList();
1463 Variant v1 = plist->First();
1464 // Note: We can't use PEAT_AUDIOIN type check since PlatformAudioIn doesn't have that type
1465 // Instead check for generic object type
1466 PError::AssertType(v1, PEAT_OBJECT, "Argument error in function [StopAudioMonitor(<monitor>)]: ");
1467
1468 PlatformAudioIn * myAudio = dynamic_cast<PlatformAudioIn*>(v1.GetComplexData()->GetObject().get());
1469 if(!myAudio) {
1470 PError::SignalFatalError("Invalid audio monitor object in StopAudioMonitor()");
1471 return Variant(false);
1472 }
1473
1474 // CloseAudio() does full cleanup: pause + close SDL device + clear globals
1475 // This is critical to free the audio hardware for subsequent GetVocalResponseTime() calls
1476 myAudio->CloseAudio();
1477 std::cout << "Audio monitor stopped and closed\n";
1478 return Variant(true);
1479
1480#else
1481 PError::SignalFatalError("Audio Input not available on this version of PEBL.");
1482 return Variant(false);
1483#endif
1484}
1485
1486
1487// Get audio statistics for the most recent N milliseconds
1488// Returns [energy, power, rmssd] as a list
1490{
1491#ifdef PEBL_AUDIOIN
1492 PList * plist = v.GetComplexData()->GetList();
1493
1494 Variant v1 = plist->First();
1495 PError::AssertType(v1, PEAT_OBJECT, "Argument error in first parameter of function [GetAudioStats(<monitor>, <window-ms>)]: ");
1496
1497 PlatformAudioIn * myAudio = dynamic_cast<PlatformAudioIn*>(v1.GetComplexData()->GetObject().get());
1498 if(!myAudio) {
1499 PError::SignalFatalError("Invalid audio monitor object in GetAudioStats()");
1500 // Return [0, 0, 0]
1501 PList * result = new PList();
1502 result->PushBack(Variant(0.0));
1503 result->PushBack(Variant(0.0));
1504 result->PushBack(Variant(0.0));
1506 return Variant(new PComplexData(baseresult));
1507 }
1508
1509 Variant v2 = plist->Nth(2);
1510 PError::AssertType(v2, PEAT_NUMBER, "Argument error in second parameter of function [GetAudioStats(<monitor>, <window-ms>)]: ");
1511
1512 int windowMs = (int)v2;
1513
1514 // Call the PlatformAudioIn method to get stats
1515 return myAudio->GetRecentAudioStats(windowMs);
1516
1517#else
1518 PError::SignalFatalError("Audio Input not available on this version of PEBL.");
1519 // Return [0, 0, 0]
1520 PList * result = new PList();
1521 result->PushBack(Variant(0.0));
1522 result->PushBack(Variant(0.0));
1523 result->PushBack(Variant(0.0));
1525 return Variant(new PComplexData(baseresult));
1526#endif
1527}
1528
1529
1531{
1532 PError::SignalFatalError("Function [MakeSquareWave] Not implemented.");
1533
1534 return Variant(false);
1535}
1536
1537
1539{
1540 PError::SignalFatalError("Function [MakeSawtoothWave] Not implemented.");
1541 return Variant(false);
1542}
1543
1545{
1546 PError::SignalFatalError("Function [MakeChirp] Not implemented.");
1547 return Variant(false);
1548}
1549
1550
1551
1553{
1554 // v[1] should be X, v[2] should be Y
1555 // v[3] should be dx, v[4] should be dy
1556 // v[5] should be the color.
1557 PList * plist = v.GetComplexData()->GetList();
1558
1559 PError::AssertType(plist->First(), PEAT_NUMBER, "Argument error in first parameter of function [Line(<x>, <y>, <dx>, <dy>, <color>)]: ");
1560 int x = plist->First(); //plist->PopFront();
1561
1562 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [Line(<x>, <y>, <dx>, <dy>, <color>)]: ");
1563 int y = plist->Nth(2); //plist->PopFront();
1564
1565 PError::AssertType(plist->Nth(3), PEAT_NUMBER, "Argument error in third parameter of function [Line(<x>, <y>, <dx>, <dy>, <color>)]: ");
1566 int dx = plist->Nth(3);// plist->PopFront();
1567
1568 PError::AssertType(plist->Nth(4), PEAT_NUMBER, "Argument error in fourth parameter of function [Line(<x>, <y>, <dx>, <dy>, <color>)]: ");
1569 int dy = plist->Nth(4);// plist->PopFront();
1570
1571 PError::AssertType(plist->Nth(5), PEAT_COLOR, "Argument error in fifth parameter of function [Line(<x>, <y>, <dx>, <dy>, <color>)]: ");
1572 Variant color = plist->Nth(5);// plist->PopFront();
1573
1575 PComplexData * pcd = new PComplexData(myLine);
1576 Variant tmp = Variant(pcd);
1577 delete pcd;
1578 pcd=NULL;
1579 return tmp;
1580 }
1581
1582
1583
1585{
1586 // v[1] should be X, v[2] should be Y
1587 // v[3] should be dx, v[4] should be dy
1588 // v[5] should be the color.
1589 PList * plist = v.GetComplexData()->GetList();
1590
1591 PError::AssertType(plist->First(), PEAT_NUMBER, "Argument error in first parameter of function [ThickLine(<x1>, <y1>, <x2>, <y2>, <thickness>,<color>)]: ");
1592 int x1 = plist->First(); //plist->PopFront();
1593
1594 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [ThickLine(<x1>, <y1>, <x2>, <y2>, <thickness>,<color>)]: ");
1595 int y1 = plist->Nth(2); //plist->PopFront();
1596
1597 PError::AssertType(plist->Nth(3), PEAT_NUMBER, "Argument error in third parameter of function [ThickLine(<x1>, <y1>, <x2>, <y2>, <thickness>,<color>)]: ");
1598 int x2 = plist->Nth(3);// plist->PopFront();
1599
1600 PError::AssertType(plist->Nth(4), PEAT_NUMBER, "Argument error in fourth parameter of function [ThickLine(<x1>, <y1>, <x2>, <y2>, <thickness>,<color>)]: ");
1601 int y2 = plist->Nth(4);// plist->PopFront();
1602
1603 PError::AssertType(plist->Nth(5), PEAT_NUMBER, "Argument error in fifth parameter of function [ThickLine(<x1>, <y1>, <x2>, <y2>, <thickness>,<color>)]: ");
1604 int thickness = plist->Nth(5);// plist->PopFront();
1605
1606
1607 PError::AssertType(plist->Nth(6), PEAT_COLOR, "Argument error in sixth parameter of function [ThickLine(<x1>, <y1>, <x2>, <y2>, <thickness>,<color>)]: ");
1608 Variant color = plist->Nth(6);// plist->PopFront();
1609
1610 counted_ptr<PEBLObjectBase> myLine = counted_ptr<PEBLObjectBase>(new PlatformThickLine(x1,y1,x2,y2,thickness,color));
1611 PComplexData * pcd = new PComplexData(myLine);
1612 Variant tmp = Variant(pcd);
1613 delete pcd;
1614 pcd=NULL;
1615 return tmp;
1616 }
1617
1618
1619
1620
1622{
1623
1624 //
1625 // v[1] should be X, v[2] shoud be Y
1626 // v[3] should be dx, v[4] should be dy
1627 // v[5] should be the color, v[6] should be whether it is filled.
1628 PList * plist = v.GetComplexData()->GetList();
1629
1630 PError::AssertType(plist->First(), PEAT_NUMBER, "Argument error in first parameter of function [Rectangle(<x>, <y>, <dx>, <dy>, <color>, <filled>)]: ");
1631 int x = plist->First(); //plist->PopFront();
1632
1633 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [Rectangle(<x>, <y>, <dx>, <dy>, <color>, <filled>)]: ");
1634 int y = plist->Nth(2);// plist->PopFront();
1635
1636 PError::AssertType(plist->Nth(3), PEAT_NUMBER, "Argument error in third parameter of function [Rectangle(<x>, <y>, <dx>, <dy>, <color>, <filled>)]: ");
1637 int dx = plist->Nth(3);// plist->PopFront();
1638
1639 PError::AssertType(plist->Nth(4), PEAT_NUMBER, "Argument error in fourth parameter of function [Rectangle(<x>, <y>, <dx>, <dy>, <color>, <filled>)]: ");
1640 int dy = plist->Nth(4); //plist->PopFront();
1641
1642 PError::AssertType(plist->Nth(5), PEAT_COLOR, "Argument error in fifth parameter of function [Rectangle(<x>, <y>, <dx>, <dy>, <color>, <filled>)]: ");
1643 Variant color = plist->Nth(5);// plist->PopFront();
1644
1645 PError::AssertType(plist->Nth(6), PEAT_NUMBER, "Argument error in sixth parameter of function [Rectangle(<x>, <y>, <dx>, <dy>, <color>, <filled>)]: ");
1646 int filled = plist->Nth(6); //plist->PopFront();
1647
1649 PComplexData * pcd = new PComplexData(myRect);
1650 Variant tmp = Variant(pcd);
1651 delete pcd;
1652 pcd=NULL;
1653 return tmp;
1654
1655
1656}
1657
1658
1659
1660
1662{
1663 // v[1] should be X, v[2] shoud be Y
1664 // v[3] should be dx, v[4] should be dy
1665 // v[5] should be the color, v[6] should be whether it is filled.
1666 PList * plist = v.GetComplexData()->GetList();
1667
1668 PError::AssertType(plist->First(), PEAT_NUMBER, "Argument error in first parameter of function [Square(<x>, <y>, <size>, <color>, <filled>)]: ");
1669 int x = plist->First(); //plist->PopFront();
1670
1671 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [Square(<x>, <y>, <size>, <color>, <filled>)]: ");
1672 int y = plist->Nth(2);// plist->PopFront();
1673
1674 PError::AssertType(plist->Nth(3), PEAT_NUMBER, "Argument error in third parameter of function [Square(<x>, <y>, <size>, <color>, <filled>)]: ");
1675 int size = plist->Nth(3); //plist->PopFront();
1676
1677 PError::AssertType(plist->Nth(4), PEAT_COLOR, "Argument error in fourth parameter of function [Square(<x>, <y>, <size>, <color>, <filled>)]: ");
1678
1679 Variant color = plist->Nth(4);// plist->PopFront();
1680
1681 PError::AssertType(plist->Nth(5), PEAT_NUMBER, "Argument error in fifth parameter of function [Square(<x>, <y>, <size>, <color>, <filled>)]: ");
1682 int filled = plist->Nth(5);// plist->PopFront();
1683
1684 counted_ptr<PEBLObjectBase> mySquare = counted_ptr<PEBLObjectBase>(new PlatformSquare(x,y,size,color,filled));
1685 PComplexData * pcd = new PComplexData(mySquare);
1686 Variant tmp = Variant(pcd);
1687 delete pcd;
1688 pcd=NULL;
1689 return tmp;
1690}
1691
1692
1694{
1695
1696 // v[1] should be X, v[2] shoud be Y
1697 // v[3] should be dx, v[4] should be dy
1698 // v[5] should be the color.
1699 PList * plist = v.GetComplexData()->GetList();
1700
1701 PError::AssertType(plist->First(), PEAT_NUMBER, "Argument error in first parameter of function [Ellipse(<x>, <y>, <rx>, <ry>, <color>, <filled>)]: ");
1702 int x = plist->First();// plist->PopFront();
1703
1704 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [Ellipse(<x>, <y>, <rx>, <ry>, <color>, <filled>)]: ");
1705 int y = plist->Nth(2); //plist->PopFront();
1706
1707 PError::AssertType(plist->Nth(3), PEAT_NUMBER, "Argument error in third parameter of function [Ellipse(<x>, <y>, <rx>, <ry>, <color>, <filled>)]: ");
1708 int rx = plist->Nth(3); //plist->PopFront();
1709
1710 PError::AssertType(plist->Nth(4), PEAT_NUMBER, "Argument error in fourth parameter of function [Ellipse(<x>, <y>, <rx>, <ry>, <color>, <filled>)]: ");
1711 int ry = plist->Nth(4);// plist->PopFront();
1712
1713 PError::AssertType(plist->Nth(5), PEAT_COLOR, "Argument error in fifth parameter of function [Ellipse(<x>, <y>, <rx>, <ry>, <color>, <filled>)]: ");
1714 Variant color = plist->Nth(5);// plist->PopFront();
1715
1716 PError::AssertType(plist->Nth(6), PEAT_NUMBER, "Argument error in sixth parameter of function [Ellipse(<x>, <y>, <rx>, <ry>, <color>, <filled>)]: ");
1717 int filled = plist->Nth(6);// plist->PopFront();
1718
1719
1720 counted_ptr<PEBLObjectBase> myEllipse = counted_ptr<PEBLObjectBase>(new PlatformEllipse(x,y,rx,ry,color,filled));
1721 PComplexData * pcd = new PComplexData(myEllipse);
1722 Variant tmp = Variant(pcd);
1723 delete pcd;
1724 pcd=NULL;
1725 return tmp;
1726
1727
1728}
1729
1730
1731
1732
1734{
1735
1736 // v[1] should be X, v[2] shoud be Y
1737 // v[3] should be dx, v[4] should be dy
1738 // v[5] should be the color.
1739 PList * plist = v.GetComplexData()->GetList();
1740
1741 PError::AssertType(plist->First(), PEAT_NUMBER, "Argument error in first parameter of function [Circle(<x>, <y>, <rx>, <color>)]: ");
1742 int x = plist->First();// plist->PopFront();
1743
1744 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [Circle(<x>, <y>, <rx>, <color>)]: ");
1745 int y = plist->Nth(2);// plist->PopFront();
1746
1747 PError::AssertType(plist->Nth(3), PEAT_NUMBER, "Argument error in third parameter of function [Circle(<x>, <y>, <r>,, <color>)]: ");
1748 int r = plist->Nth(3);// plist->PopFront();
1749
1750
1751 PError::AssertType(plist->Nth(4), PEAT_COLOR, "Argument error in fourth parameter of function [Circle(<x>, <y>, <rx>, <color>)]: ");
1752 Variant color = plist->Nth(4);// plist->PopFront();
1753
1754 PError::AssertType(plist->Nth(5), PEAT_NUMBER, "Argument error in fifth parameter of function [Circle(<x>, <y>, <rx>, <ry>, <color>, <filled>)]: ");
1755 int filled = plist->Nth(5);// plist->PopFront();
1756
1757
1759 PComplexData * pcd = new PComplexData(myCircle);
1760 Variant tmp = Variant(pcd);
1761 delete pcd;
1762 pcd=NULL;
1763 return tmp;
1764
1765}
1766
1767
1769{
1770
1771 // v[1] should be X, v[2] shoud be Y
1772 // v[3] list-of-x-points
1773 // v[4] list-of-y-points
1774 // v[5] should be should be color
1775 // v[6] should be whether filled
1776 PList * plist = v.GetComplexData()->GetList();
1777
1778 PError::AssertType(plist->First(), PEAT_NUMBER, "Argument error in first parameter of function [Polygon(<x>, <y>, <xpoints>, <ypoints>, <color>, <filled>)]: ");
1779 int x = plist->First(); //plist->PopFront();
1780
1781 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [Polygon(<x>, <y>,<xpoints>, <ypoints>, <color>, <filled>)]: ");
1782 int y = plist->Nth(2); //plist->PopFront();
1783
1784 PError::AssertType(plist->Nth(3), PEAT_LIST, "Argument error in third parameter of function [Polygon(<x>, <y>, <xpoints>, <ypoints>, <color>, <filled>)]: ");
1785 Variant xpoints = plist->Nth(3); //plist->PopFront();
1786
1787 PError::AssertType(plist->Nth(4), PEAT_LIST, "Argument error in fourth parameter of function [Polygon(<x>, <y>, <xpoints>, <ypoints>, <color>, <filled>)]: ");
1788 Variant ypoints = plist->Nth(4);// plist->PopFront();
1789
1790 PError::AssertType(plist->Nth(5), PEAT_COLOR, "Argument error in fifth parameter of function [Polygon(<x>, <y>, <xpoints>, <ypoints>, <color>, <filled>)]: ");
1791 Variant color = plist->Nth(5);// plist->PopFront();
1792
1793 PError::AssertType(plist->Nth(6), PEAT_NUMBER, "Argument error in sixth parameter of function [Polygon(<x>, <y>, <xpoints>, <ypoints>, <color>, <filled>)]: ");
1794 int filled = plist->Nth(6);// plist->PopFront();
1795
1796 counted_ptr<PEBLObjectBase> myPolygon = counted_ptr<PEBLObjectBase>(new PlatformPolygon(x,y,xpoints,ypoints,color,filled));
1797 PComplexData * pcd = new PComplexData(myPolygon);
1798 Variant tmp = Variant(pcd);
1799 delete pcd;
1800 pcd=NULL;
1801 return tmp;
1802
1803}
1804
1805
1806
1807
1809{
1810
1811 // v[1] should be X, v[2] shoud be Y
1812 // v[3] should be dx, v[4] should be dy
1813 // v[5] should be the color.
1814 PList * plist = v.GetComplexData()->GetList();
1815
1816 PError::AssertType(plist->First(), PEAT_NUMBER, "Argument error in first parameter of function [Bezier(<x>, <y>, <xpoints>, <ypoints>, <steps>, <color>)]: ");
1817 int x = plist->First(); //plist->PopFront();
1818
1819 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [Bezier(<x>, <y>,<xpoints>, <ypoints>, <steps>, <color>)]: ");
1820 int y = plist->Nth(2); //plist->PopFront();
1821
1822 PError::AssertType(plist->Nth(3), PEAT_LIST, "Argument error in third parameter of function [Bezier(<x>, <y>, <xpoints>, <ypoints>, <steps>, <color>)]: ");
1823 Variant xpoints = plist->Nth(3); //plist->PopFront();
1824
1825 PError::AssertType(plist->Nth(4), PEAT_LIST, "Argument error in fourth parameter of function [Bezier(<x>, <y>, <xpoints>, <ypoints>, <steps>, <color>)]: ");
1826 Variant ypoints = plist->Nth(4);// plist->PopFront();
1827
1828 PError::AssertType(plist->Nth(5), PEAT_NUMBER, "Argument error in fifth parameter of function [Bezier(<x>, <y>, <xpoints>, <ypoints>, <steps>, <color>)]: ");
1829 int steps = plist->Nth(5);// plist->PopFront();
1830
1831 PError::AssertType(plist->Nth(6), PEAT_COLOR, "Argument error in sixth parameter of function [Bezier(<x>, <y>, <xpoints>, <ypoints>, <steps>, <color>)]: ");
1832 Variant color = plist->Nth(6);// plist->PopFront();
1833
1834
1835 counted_ptr<PEBLObjectBase> myBezier = counted_ptr<PEBLObjectBase>(new PlatformBezier(x,y,xpoints,ypoints,steps,color));
1836 PComplexData * pcd = new PComplexData(myBezier);
1837
1838 Variant tmp = Variant(pcd);
1839 delete pcd;
1840 pcd=NULL;
1841 return tmp;
1842
1843
1844}
1845
1846
1847
1848
1849
1851{
1852
1853 // v[1] should be an object,
1854 // v[2] shoud be rotation
1855 // v[3] should be xzoom, v[4] should be yzoom
1856 // v[5] should be whether to anti-alias.
1857
1858 PList * plist = v.GetComplexData()->GetList();
1859
1860 PError::AssertType(plist->First(), PEAT_WIDGET, "Argument error in first parameter of function [ROTOZOOM(<widget>,<rotation>,<xzoom>, <yzoom>, <smooth>)]: ");
1861 Variant v1 = plist->First(); //plist->PopFront();
1862 PlatformWidget * widget = dynamic_cast<PlatformWidget*>(v1.GetComplexData()->GetObject().get());
1863
1864
1865
1866 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [ROTOZOOM(<widget>,<rotation>,<xzoom>, <yzoom>, <smooth>)]: ");
1867 Variant r = plist->Nth(2); //plist->PopFront();
1868
1869 PError::AssertType(plist->Nth(3), PEAT_NUMBER, "Argument error in third parameter of function [ROTOZOOM(<widget>,<rotation>,<xzoom>, <yzoom>, <smooth>)]: ");
1870 Variant x = plist->Nth(3); //plist->PopFront();
1871
1872
1873 PError::AssertType(plist->Nth(4), PEAT_NUMBER, "Argument error in fourth parameter of function [ROTOZOOM(<widget>,<rotation>,<xzoom>, <yzoom>, <smooth>)]: ");
1874 Variant y = plist->Nth(4); //plist->PopFront();
1875
1876 PError::AssertType(plist->Nth(5), PEAT_NUMBER, "Argument error in fifth parameter of function [ROTOZOOM(<widget>,<rotation>,<xzoom>, <yzoom>, <smooth>)]: ");
1877 int smooth = plist->Nth(5);// plist->PopFront();
1878
1879 bool result = widget->RotoZoom((pDouble)r,(pDouble)x,(pDouble)y,smooth);
1880
1881
1882 if(!result)PError::SignalFatalError("Rotozoom failed.");
1883
1884 return v1.GetComplexData();
1885}
1886
1887
1888
1889//define MakeGabor(size,freq,sd, angle,phase,bglev)
1890
1891#if 0
1892Variant PEBLObjects::Gabor(Variant v)
1893{
1894
1895 //
1896 // v[1] should be X, v[2] shoud be Y
1897 // v[3] should be dx, v[4] should be dy
1898 // v[5] should be the color, v[6] should be whether it is filled.
1899 PList * plist = v.GetComplexData()->GetList();
1900
1901 PError::AssertType(plist->First(), PEAT_NUMBER, "Argument error in first parameter of function [MakeCanvas(<width>, <height>, <color>)]: ");
1902 int width = plist->First(); //plist->PopFront();
1903
1904 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [MakeCanvas(<width>, <height>, <color>)]: ");
1905 int height = plist->Nth(2);// plist->PopFront();
1906
1907
1908 PError::AssertType(plist->Nth(3), PEAT_COLOR, "Argument error in fifth parameter of function [MakeCanvas(<x>, <y>, <dx>, <dy>, <color>)]: ");
1909 Variant color = plist->Nth(3);// plist->PopFront();
1910
1911
1912 int size = 100;
1913 double freq = 10;
1914 double sd = 12;
1915 double angle = 0;
1916 double phase = 0;
1917 int bglev = 128;
1918
1919 //Make a canvas:
1921 PComplexData * pcd = new PComplexData(myCanvas);
1922
1923
1924
1925 Variant tmp = Variant(pcd);
1926 delete pcd;
1927 pcd=NULL;
1928 return tmp;
1929
1930
1931
1932}
1933
1934#endif
1935
1937{
1938
1939#ifdef PEBL_MOVIES
1940
1941 // v[1] should be name of movie
1942 // v[2] should be width; v[3] should be height.
1943 PList * plist = v.GetComplexData()->GetList();
1944
1945 PError::AssertType(plist->First(), PEAT_STRING, "Argument error in first parameter of function [LoadMovie(<filename>,<window>,<width>, <height>)]: ");
1946 Variant filename = plist->First();
1947
1948 Variant v2 = plist->Nth(2); //plist->PopFront();
1949 PError::AssertType(v2, PEAT_WIDGET, "Argument error in second parameter of function [LoadMovie(<filename>,<window>,<width>, <height>)]: ");
1950
1951 PlatformWindow * window = dynamic_cast<PlatformWindow*>(v2.GetComplexData()->GetObject().get());
1952
1953
1954
1955 PError::AssertType(plist->Nth(3), PEAT_NUMBER, "Argument error in second parameter of function [LoadMovie(<filename>,<window>,<width>, <height>)]: ");
1956 int width = plist->Nth(3);
1957
1958
1959 PError::AssertType(plist->Nth(4), PEAT_NUMBER, "Argument error in second parameter of function [LoadMovie(<filename>,<window>,<width>, <height>)]: ");
1960 int height = plist->Nth(4);
1961
1962
1963 PlatformMovie* myMovie = new PlatformMovie();
1964 myMovie->LoadMovie(filename,window,width,height);
1965
1966 // myMovie->StartPlayback();
1967
1969 PComplexData * pcd = new PComplexData(tmpMov);
1970 Variant tmp = Variant(pcd);
1971 delete pcd;
1972 pcd=NULL;
1973 return tmp;
1974#else
1975 return Variant(false);
1976#endif
1977
1978}
1979
1980
1981
1982
1984{
1985#ifdef PEBL_MOVIES
1986 // v[1] should be name of movie
1987 // v[2] should be width; v[3] should be height.
1988 PList * plist = v.GetComplexData()->GetList();
1989
1990 PError::AssertType(plist->First(), PEAT_STRING, "Argument error in first parameter of function [LoadAudioFile(<filename>)]: ");
1991 Variant filename = plist->First();
1992
1993
1994 PlatformMovie* myMovie = new PlatformMovie();
1995 myMovie->LoadAudioFile(filename);
1996
1997 // myMovie->StartPlayback();
1998
2000 PComplexData * pcd = new PComplexData(tmpMov);
2001 Variant tmp = Variant(pcd);
2002 delete pcd;
2003 pcd=NULL;
2004 return tmp;
2005#else
2006 return false;
2007#endif
2008}
2009
2010
2011
2013{
2014#ifdef PEBL_MOVIES
2015 PList * plist = v.GetComplexData()->GetList();
2016
2017 PError::AssertType(plist->First(), PEAT_MOVIE, "Argument error in first parameter of function [StartPlayback(<movie>)]: ");
2018
2019 Variant v1 = plist->First();
2020 PlatformMovie * myMovie = dynamic_cast<PlatformMovie*>(v1.GetComplexData()->GetObject().get());
2021 myMovie->StartPlayback();
2022 return Variant(true);
2023#else
2024 return false;
2025#endif
2026}
2027
2028
2030{
2031
2032#ifdef PEBL_MOVIES
2033 PList * plist = v.GetComplexData()->GetList();
2034
2035 PError::AssertType(plist->First(), PEAT_MOVIE, "Argument error in first parameter of function [PausePlayback(<movie>)]: ");
2036
2037
2038 Variant v1 = plist->First();
2039 PlatformMovie * myMovie = dynamic_cast<PlatformMovie*>(v1.GetComplexData()->GetObject().get());
2040 myMovie->PausePlayback();
2041 return Variant(true);
2042#else
2043 return false;
2044#endif
2045}
2046
2047
2048
2049
2051{
2052 PList * plist = v.GetComplexData()->GetList();
2053 std::string name = plist->First();// plist->PopFront();
2054
2055 PCustomObject* myobj = new PCustomObject(name);
2057 PComplexData * pcd = new PComplexData(tmpObject);
2058 Variant tmp = Variant(pcd);
2059 delete pcd;
2060 pcd=NULL;
2061 return tmp;
2062
2063}
2064
2065
2066//Currently, this works with locally-connected eyetribe
2067//tracker using gazelib. In theory, it could work more generally
2069{
2070
2071#ifdef PEBL_GAZELIB
2072 //this should offer setting the address and port (default is 127.0.0.1/6555)
2073 PEyeTracker * pet = new PEyeTracker();
2074
2076
2077 PComplexData * pcd = new PComplexData(tmpObject);
2078 Variant tmp = Variant(pcd);
2079 delete pcd;
2080 pcd=NULL;
2081 return tmp;
2082#else
2083 return Variant(0);
2084#endif
2085
2086}
2087
2088
2089
2090// This returns a 'custom' object related to the current state of the
2091// eye position.
2092//
2094{
2095
2096#ifdef PEBL_GAZELIB
2097 PList * plist = v.GetComplexData()->GetList();
2098 Variant obj = plist->First();
2099
2100 PEyeTracker * pet = dynamic_cast<PEyeTracker*>(obj.GetComplexData()->GetObject().get());
2101
2102 gtl::GazeData * gd = pet->GetGazeFrame();
2103
2104 Variant obj2 = ConvertGazeData(*gd);
2105 delete gd;
2106 gd = NULL;
2107
2108 return obj2;
2109#else
2110 return Variant(0);
2111#endif
2112}
2113
2115{
2116
2117
2118#ifdef PEBL_GAZELIB
2119
2120
2121 PList * plist = v.GetComplexData()->GetList();
2122 Variant obj = plist->First();
2123
2124 PEyeTracker * pet = dynamic_cast<PEyeTracker*>(obj.GetComplexData()->GetObject().get());
2125 Variant fname = plist->Nth(2);
2126
2127 PEBLGaze * pg = new PEBLGaze(fname);
2128#endif
2129
2130 return Variant(1);
2131
2132}
#define NULL
Definition BinReloc.cpp:317
#define pDouble
Definition Defs.h:7
PEBLVideoDepth
Definition Globals.h:69
PEBLVideoMode
Definition Globals.h:58
Evaluator * myEval
Definition PEBL.cpp:188
PlatformEnvironment * myEnv
Definition PEBL.cpp:189
PlatformEventQueue * gEventQueue
@ PEAT_FONT
Definition PError.h:57
@ PEAT_TEXTOBJECT
Definition PError.h:66
@ PEAT_COLOR
Definition PError.h:54
@ PEAT_LIST
Definition PError.h:61
@ PEAT_TEXTBOX
Definition PError.h:67
@ PEAT_INTEGER
Definition PError.h:44
@ PEAT_WIDGET
Definition PError.h:69
@ PEAT_WINDOW
Definition PError.h:70
@ PEAT_STRING
Definition PError.h:46
@ PEAT_OBJECT
Definition PError.h:63
@ PEAT_AUDIOOUT
Definition PError.h:53
@ PEAT_NUMBER
Definition PError.h:43
@ PEAT_MOVIE
Definition PError.h:71
static VariableMap gGlobalVariableMap
virtual bool SetPanning(const double left, const double right)
Definition PAudioOut.h:52
Variant GetProperty(std::string prop) const
counted_ptr< PEBLObjectBase > GetObject() const
PList * GetList() const
bool IsLabel() const
void SetProperty(std::string, Variant v)
bool PropertyExists(std::string prop) const
bool IsThickLine() const
This class simply represent an abstract text-based object.
virtual std::ostream & PrintProperties(std::ostream &out)
virtual Variant GetPropertyList()
virtual bool AddWindow(PWindow *window)
Definition PList.h:45
Variant Nth(unsigned int n)
Definition PList.cpp:181
unsigned long Length() const
Definition PList.h:89
void PushBack(const Variant &v)
Definition PList.cpp:149
Variant First()
Definition PList.cpp:169
This class is the basic generic text box.
Definition PTextBox.h:40
virtual std::string GetText() const
Definition PTextObject.h:56
virtual void SetPosition(pInt x, pInt y)
This sets the widget's position on its parent widget.
Definition PWidget.cpp:220
virtual pInt GetWidth() const
Definition PWidget.h:85
virtual void Show()
Definition PWidget.cpp:396
virtual pInt GetHeight() const
Definition PWidget.h:86
virtual bool SetProperty(std::string, Variant v)
Definition PWidget.cpp:142
virtual void Hide()
Definition PWidget.cpp:402
virtual PWidget * GetParent()
Definition PWidget.h:63
virtual bool IsParent(PWidget *parent)
Definition PWidget.cpp:323
void SaveBufferToWave(Variant filename)
bool LoadSoundFromData(Uint8 *buffer, long unsigned int size, SDL_AudioSpec *spec, Uint32 recordpos=0)
bool CreateSineWave(float freq, double length, int amplitude)
bool LoadSoundFile(const char *filename)
counted_ptr< AudioInfo > GetAudioInfo()
Validator platform canvas - no pixel buffer, used only for compilation.
void Initialize()
This method initiates everything needed to display the main window.
Validator platform image box - no image loading, used only for compilation.
virtual bool LoadImage(const std::string &imagefilename)
Validator platform label - no rendering, used only for compilation.
virtual void SetText(const std::string &text)
virtual void SetPosition(pInt x, pInt y)
This sets the widget's position on its parent widget.
virtual void SetFont(counted_ptr< PEBLObjectBase > font)
Validator platform textbox - no rendering, used only for compilation.
virtual void SetFont(counted_ptr< PEBLObjectBase > font)
virtual void SetText(std::string text)
virtual void SetEditable(bool val)
virtual bool SetProperty(std::string, Variant v)
virtual void SetPosition(pInt x, pInt y)
This sets the widget's position on its parent widget.
virtual void SetPosition(pInt x, pInt y)
This sets the widget's position on its parent widget.
virtual void Sleep(unsigned long int msecs)
virtual bool AddSubWidget(PlatformWidget *widget)
bool SetPoint(int x, int y, PColor col)
virtual bool Draw()
This method initiates everything needed to display the main window
virtual bool RemoveSubWidget(PlatformWidget *widget)
virtual bool RotoZoom(double angle, double zoomx, double zoomy, int smooth)
This uses the SDL_gfx package to 'rotozoom'.
PColor GetPixel(int x, int y)
bool Resize(int w, int h)
bool Initialize(PEBLVideoMode mode, PEBLVideoDepth vdepth, bool windowed, bool resizeable, unsigned int width, unsigned int height)
This method initiates everything needed to display the main window.
long int DrawFor(unsigned int cycles)
virtual void SetBackgroundColor(const PColor &color)
Variant RetrieveValue(const std::string &varname)
bool IsComplexData() const
Definition Variant.cpp:984
pInt GetInteger() const
Definition Variant.cpp:997
bool IsStackSignal() const
Definition Variant.cpp:989
std::string GetString() const
Definition Variant.cpp:1056
PComplexData * GetComplexData() const
Definition Variant.cpp:1299
X * get() const
Definition rc_ptrs.h:110
PlatformTimer myTimer
Variant SetEyeTrackerHandler(Variant v)
Variant SetPanning(Variant v)
Variant GetPixelColor(Variant v)
Variant SetEditable(Variant v)
Variant StartAudioMonitor(Variant v)
Variant DrawFor(Variant v)
Variant MakeColorRGB(Variant v)
Variant Line(Variant v)
Variant Move(Variant v)
Variant PrintProperties(Variant v)
Variant GetEyeObject(Variant v)
Variant ConnectEyeTracker(Variant v)
Variant GetPropertyList(Variant v)
void MakeEnvironment(PEBLVideoMode mode, PEBLVideoDepth depth, bool windowed, bool resizeable, bool unicode)
This function instantiates the namespace-viewable.
Variant Rectangle(Variant v)
Variant GetAudioStats(Variant v)
Variant MakeLabel(Variant v)
Variant MakeWindow(Variant v)
Variant ThickLine(Variant v)
Variant MakeCustomObject(Variant v)
Variant RotoZoom(Variant v)
Variant GetParent(Variant v)
Variant SetText(Variant v)
Variant RecordToBuffer(Variant v)
Variant SaveAudioToWaveFile(Variant v)
Variant SetPlayRepeats(Variant v)
Variant StartPlayback(Variant v)
Variant PlayForeground(Variant v)
Variant GetProperty(Variant v)
Variant MakeAudioInputBuffer(Variant v)
Variant MakeFont(Variant v)
Variant PausePlayback(Variant v)
Variant Bezier(Variant v)
Variant SetFont(Variant v)
Variant LoadMovie(Variant v)
Variant RemoveObject(Variant v)
This removes a child widget from the parent widget.
Variant SetPoint(Variant v)
Variant GetSize(Variant v)
Variant GetVocalResponseTime(Variant v)
Variant GetLineBreaks(Variant v)
Variant Draw(Variant v)
Variant Polygon(Variant v)
Variant Stop(Variant v)
Variant ResizeWindow(Variant v)
Variant Circle(Variant v)
Variant MakeSawtoothWave(Variant v)
Variant MakeTextBox(Variant v)
Variant PropertyExists(Variant v)
Variant MakeCanvas(Variant v)
Variant Ellipse(Variant v)
Variant GetText(Variant v)
Variant Hide(Variant v)
Variant LoadSound(Variant v)
Variant MakeColor(Variant v)
Variant Square(Variant v)
Variant LoadAudioFile(Variant v)
Variant SetCursorPosition(Variant v)
Variant StopAudioMonitor(Variant v)
Variant MakeSineWave(Variant v)
Variant SetProperty(Variant v)
Variant PlayBackground(Variant v)
Variant Show(Variant v)
Variant GetCursorPosition(Variant v)
Variant MakeChirp(Variant v)
Variant MakeImage(Variant v)
Variant MakeSquareWave(Variant v)
Variant AddObject(Variant v)
This function adds a widget to a parent widget.
std::string ToUpper(const std::string &text)
void SignalWarning(const std::string &message)
Definition PError.cpp:119
void AssertType(Variant v, int type, const std::string &outsidemessage)
void SignalFatalError(const std::string &message)
int count
Definition test.cpp:12