Jamoma API  0.6.0.a19
TTExplorer.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup modularLibrary
4  *
5  * @brief A Namespace Explorer Object
6  *
7  * @details
8  *
9  * @authors Théo de la Hogue
10  *
11  * @copyright © 2010, Théo de la Hogue @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #include "TTExplorer.h"
18 
19 #define thisTTClass TTExplorer
20 #define thisTTClassName "Explorer"
21 #define thisTTClassTags "explorer"
22 
23 TT_MODULAR_CONSTRUCTOR,
24 mNamespace(kTTSym_none),
25 mAddress(kTTAdrsEmpty),
26 mOutput(kTTSym_descendants),
27 mUpdate(YES),
28 mSort(kTTSym_alphabetic),
29 mDepth(0),
30 mDirectory(NULL),
31 mFilterList(NULL),
32 mTempNode(NULL),
33 mResult(NULL)
34 {
35  if(arguments.size() >= 1)
36  mReturnValueCallback = arguments[0];
37 
38  // It is possible to pass a default filter bank
39  if(arguments.size() >= 2)
40  mFilterBank = TTHashPtr((TTPtr)arguments[1]);
41  else
42  mFilterBank = new TTHash();
43 
44  if(arguments.size() >= 3)
45  mReturnSelectionCallback = arguments[2];
46 
48 
54 
55  registerAttribute(TTSymbol("filterList"), kTypeLocalValue, NULL, (TTGetterMethod)&TTExplorer::getFilterList, (TTSetterMethod)&TTExplorer::setFilterList);
56 
57  addMessage(Explore);
59  addMessageWithArguments(SelectAll);
60  addMessageWithArguments(SelectNone);
61 
62  addMessage(SelectionRefresh);
63 
64  addMessageWithArguments(FilterSet);
65  addMessageWithArguments(FilterRemove);
66  addMessageWithArguments(FilterInfo);
67 
68  mFilterList = new TTList();
69  mResult = new TTHash();
70 }
71 
72 TTExplorer::~TTExplorer()
73 {
74  unbindAddress();
75  unbindApplication();
76 
77  delete mFilterBank;
78  delete mFilterList;
79  delete mResult;
80 }
81 
82 TTErr TTExplorer::setNamespace(const TTValue& value)
83 {
84  TTAddressItemPtr aSelection;
85  TTObject thisObject(this);
86 
87  // unregister from the former namespace
88  aSelection = TTModularSelectionLookup(mNamespace);
89 
90  if (aSelection)
91  aSelection->unregisterHandler(thisObject);
92 
93  // get new namespace
94  mNamespace = value;
95 
96  // register to the new namespace
97  aSelection = TTModularSelectionLookup(mNamespace);
98 
99  if (aSelection)
100  aSelection->registerHandler(thisObject);
101 
102  return kTTErrNone;
103 }
104 
105 TTErr TTExplorer::setOutput(const TTValue& value)
106 {
107  TTSymbol newOutput = value;
108 
109  if (newOutput == kTTSym_descendants ||
110  newOutput == kTTSym_children ||
111  newOutput == kTTSym_brothers ||
112  newOutput == kTTSym_attributes) {
113 
114  mOutput = newOutput;
115 
116  setAddress(mAddress);
117 
118  return kTTErrNone;
119  }
120  else
121  return kTTErrGeneric;
122 }
123 
124 TTErr TTExplorer::setAddress(const TTValue& value)
125 {
126  unbindAddress();
127  unbindApplication();
128 
129  // change the address
130  mAddress = value[0];
131 
132  mDirectory = accessApplicationDirectoryFrom(mAddress);
133  if (mDirectory)
134  return bindAddress();
135  else
136  return bindApplication();
137 }
138 
139 TTErr TTExplorer::setUpdate(const TTValue& value)
140 {
141  TTBoolean oldUpdate = mUpdate;
142 
143  mUpdate = value;
144 
145  // check change
146  if (mUpdate == oldUpdate)
147  return kTTErrNone;
148 
149  return setAddress(mAddress);
150 }
151 
152 TTErr TTExplorer::setSort(const TTValue& value)
153 {
154  TTSymbol oldSort = mSort;
155 
156  mSort = value;
157 
158  // check change
159  if (mSort == oldSort)
160  return kTTErrNone;
161 
162  if (mSort == kTTSym_none || mSort == kTTSym_alphabetic || mSort == kTTSym_priority)
163  return kTTErrNone;
164  else
165  return kTTErrGeneric;
166 }
167 
168 TTErr TTExplorer::setDepth(const TTValue& value)
169 {
170  TTUInt8 oldDepth = mDepth;
171 
172  mDepth = value;
173 
174  // check change
175  if (mDepth == oldDepth)
176  return kTTErrNone;
177 
178  return setAddress(mAddress);
179 }
180 
181 TTErr TTExplorer::bindAddress()
182 {
183  // it works only for absolute address
184  if (mAddress.getType() == kAddressAbsolute) {
185 
186  // change the address observer
187  if (mUpdate && mAddress != kTTAdrsEmpty) {
188 
189  // observe any creation or destruction below the address
190  mAddressObserver = TTObject("callback");
191 
192  mAddressObserver.set(kTTSym_baton, TTPtr(this)); // théo -- we have to register our self as a #TTPtr to not reference this instance otherwhise the destructor will never be called
193  mAddressObserver.set(kTTSym_function, TTPtr(&TTExplorerDirectoryCallback));
194 
195  if (mDepth)
196  mDirectory->addObserverForNotifications(mAddress, mAddressObserver, mDepth);
197  else
198  mDirectory->addObserverForNotifications(mAddress, mAddressObserver);
199  }
200 
201  return kTTErrNone;
202  }
203 
204  return kTTErrGeneric;
205 }
206 
207 TTErr TTExplorer::unbindAddress()
208 {
209  // delete the old observer
210  if (mDirectory && mAddressObserver.valid() && mAddress != kTTSymEmpty) {
211 
212  mDirectory->removeObserverForNotifications(mAddress, mAddressObserver);
213  mAddressObserver = TTObject();
214 
215  return kTTErrNone;
216  }
217 
218  return kTTErrGeneric;
219 }
220 
221 TTErr TTExplorer::bindApplication()
222 {
223  if (!mApplicationObserver.valid()) {
224 
225  mApplicationObserver = TTObject("callback");
226 
227  mApplicationObserver.set(kTTSym_baton, TTPtr(this)); // théo -- we have to register our self as a #TTPtr to not reference this instance otherwhise the destructor will never be called
228  mApplicationObserver.set(kTTSym_function, TTPtr(&TTExplorerApplicationManagerCallback));
229 
230  return TTApplicationManagerAddApplicationObserver(mAddress.getDirectory(), mApplicationObserver);
231  }
232 
233  return kTTErrGeneric;
234 }
235 
236 TTErr TTExplorer::unbindApplication()
237 {
238  TTErr err;
239 
240  if (mApplicationObserver.valid()) {
241 
242  err = TTApplicationManagerRemoveApplicationObserver(mAddress.getDirectory(), mApplicationObserver);
243 
244  mApplicationObserver = TTObject();
245  }
246 
247  mDirectory = NULL;
248 
249  return kTTErrNone;
250 }
251 
252 TTErr TTExplorer::Explore()
253 {
254  TTAddress relativeAddress;
255  TTSymbol attributeName;
256  TTList aNodeList, internalFilterList, allObjectNodes;
257  TTNodePtr aNode;
258  TTObject o;
259  TTValue v, args, none;
260  TTErr err;
261 
262  mResult->clear();
263  mLastResult.clear();
264  mTempNode = NULL;
265 
266  if (!mDirectory)
267  return kTTErrGeneric;
268 
269  // bind the right node
270  if (mOutput == kTTSym_brothers)
271  err = mDirectory->Lookup(mAddress.getParent(), aNodeList, &mTempNode);
272  else
273  err = mDirectory->Lookup(mAddress, aNodeList, &mTempNode);
274 
275  if (!err){
276 
277  // clear namespace
278  TTAddressItemPtr aSelection = TTModularSelectionLookup(mNamespace);
279  if (aSelection)
280  aSelection->clear();
281 
282  // get attributes names of the node at mAddress
283  if (mOutput == kTTSym_attributes) {
284 
285  o = mTempNode->getObject();
286  if (o.valid()) {
287  v.clear();
288  o.attributes(v);
289 
290  // memorized the result in a hash table
291  for (TTUInt32 i = 0; i < v.size(); i++) {
292  attributeName = v[i];
293  mResult->append(attributeName, none);
294  }
295  }
296  }
297 
298  // explore nodes below the address
299  else {
300 
301  // prepare filters for the exploration
302  args = TTValue((TTPtr)mFilterBank);
303  args.append((TTPtr)mFilterList);
304 
305  // explore
306  mDirectory->LookFor(&aNodeList, testNodeUsingFilter, (TTPtr)&args, allObjectNodes, &aNode, mDepth);
307 
308  // memorized the result in a hash table (the node is stored in order to sort the result)
309  for (allObjectNodes.begin(); allObjectNodes.end(); allObjectNodes.next()) {
310 
311  aNode = TTNodePtr((TTPtr)allObjectNodes.current()[0]);
312 
313  // children case :
314  if (mOutput == kTTSym_children){
315 
316  aNode->getAddress(relativeAddress, mAddress);
317 
318  // ignore address with a parent part
319  if (relativeAddress.getParent() != kTTAdrsEmpty)
320  continue;
321 
322  mResult->append(relativeAddress, TTValue((TTPtr)aNode));
323  }
324 
325  // brothers case :
326  else if (mOutput == kTTSym_brothers) {
327 
328  aNode->getAddress(relativeAddress, mAddress.getParent());
329 
330  // ignore address with a parent part
331  if (relativeAddress.getParent() != kTTAdrsEmpty)
332  continue;
333 
334  // store only the relative address for node with the same name
335  if (mAddress.getName() == relativeAddress.getName())
336  mResult->append(relativeAddress, TTValue((TTPtr)aNode));
337  }
338 
339  // any other case : store the address
340  else {
341 
342  /*if (mAddress == kTTAdrsRoot)
343  aNode->getAddress(&relativeAddress);
344  else*/
345  aNode->getAddress(relativeAddress, mAddress);
346 
347  mResult->append(relativeAddress, TTValue((TTPtr)aNode));
348  }
349  }
350  }
351 
352  // Return the value result back
353  return returnResultBack();
354  }
355 
356  return kTTErrGeneric;
357 }
358 
359 TTErr TTExplorer::Select(const TTValue& inputValue, TTValue& outputValue)
360 {
361  TTAddressItemPtr aSelection = TTModularSelectionLookup(mNamespace);
362  TTAddressItemPtr anItem = NULL;
363  TTAddress itemSymbol;
364  TTInt32 i, number;
365  TTBoolean state = NO;
366 
367  if (aSelection && inputValue.size()) {
368 
369  // set one item selection state
370  if (inputValue[0].type() == kTypeSymbol) {
371 
372  itemSymbol = inputValue[0];
373 
374  // get the item
375  if (mOutput == kTTSym_children) {
376  aSelection->find(mAddress.appendAddress(itemSymbol), &anItem);
377  anItem = anItem->getParent();
378  }
379  else if (mOutput == kTTSym_brothers)
380  aSelection->find(mAddress.appendInstance(itemSymbol), &anItem);
381 
382  else if (itemSymbol.getType() == kAddressRelative)
383  aSelection->find(mAddress.appendAddress(itemSymbol), &anItem);
384 
385  else
386  aSelection->find(itemSymbol, &anItem);
387 
388  if (anItem) {
389 
390  // set selection state
391  if (inputValue.size() == 2) {
392 
393  if (inputValue[1].type() == kTypeInt32)
394  state = inputValue[1];
395  }
396  // or switch it
397  else
398  state = !anItem->getSelection();
399 
400  // set selection state
401  anItem->setSelection(state, YES);
402 
403  // refresh all namespace handlers (TTExplorer only)
404  aSelection->iterateHandlersSendingMessage(kTTSym_SelectionRefresh);
405 
406  return kTTErrNone;
407  }
408  }
409 
410  // set all items selection state
411  else if (inputValue[0].type() == kTypeInt32 && inputValue.size() == mLastResult.size()) {
412 
413  // set all selection state
414  for (i = 0; i < (TTInt32) mLastResult.size(); i++) {
415 
416  itemSymbol = mLastResult[i];
417  number = inputValue[i];
418 
419  state = number == 1;
420 
421  // move to mAddress + itemSymbol namespace
422  if (mOutput == kTTSym_children) {
423  aSelection->find(mAddress.appendAddress(itemSymbol), &anItem);
424  anItem = anItem->getParent();
425  }
426  else if (mOutput == kTTSym_brothers)
427  aSelection->find(mAddress.appendInstance(itemSymbol), &anItem);
428 
429  else
430  aSelection->find(mAddress.appendAddress(itemSymbol), &anItem);
431 
432  if (anItem)
433  anItem->setSelection(state, YES);
434  }
435 
436  // refresh all namespace handlers (TTExplorer only)
437  aSelection->iterateHandlersSendingMessage(kTTSym_SelectionRefresh);
438 
439  return kTTErrNone;
440  }
441  }
442 
443  return kTTErrGeneric;
444 }
445 
446 TTErr TTExplorer::SelectAll()
447 {
448  TTAddressItemPtr aSelection = TTModularSelectionLookup(mNamespace);
449  TTAddressItemPtr anItem;
450  TTAddress itemSymbol;
451  TTInt32 i;
452 
453  if (aSelection) {
454  // set all selection state
455  for (i = 0; i < (TTInt32) mLastResult.size(); i++) {
456 
457  itemSymbol = mLastResult[i];
458 
459  // move to mAddress + itemSymbol namespace
460  if (mOutput == kTTSym_children) {
461  aSelection->find(mAddress.appendAddress(itemSymbol), &anItem);
462  anItem = anItem->getParent();
463  }
464  else if (mOutput == kTTSym_brothers)
465  aSelection->find(mAddress.appendInstance(itemSymbol), &anItem);
466 
467  else
468  aSelection->find(mAddress.appendAddress(itemSymbol), &anItem);
469 
470  if (anItem)
471  anItem->setSelection(YES, YES);
472  }
473 
474  // refresh all namespace handlers (TTExplorer only)
475  aSelection->iterateHandlersSendingMessage(kTTSym_SelectionRefresh);
476 
477  return kTTErrNone;
478  }
479 
480  // return selection to the owner of the explorer
481  return returnSelectionBack();
482 }
483 
484 /** Set all selection state to NO */
485 TTErr TTExplorer::SelectNone()
486 {
487  TTAddressItemPtr aSelection = TTModularSelectionLookup(mNamespace);
488  TTAddressItemPtr anItem;
489  TTAddress itemSymbol;
490  TTInt32 i;
491 
492  if (aSelection) {
493 
494  // set all selection state
495  for (i = 0; i < (TTInt32) mLastResult.size(); i++) {
496 
497  itemSymbol = mLastResult[i];
498 
499  // move to mAddress + itemSymbol namespace
500  if (mOutput == kTTSym_children) {
501  aSelection->find(mAddress.appendAddress(itemSymbol), &anItem);
502  anItem = anItem->getParent();
503  }
504  else if (mOutput == kTTSym_brothers)
505  aSelection->find(mAddress.appendInstance(itemSymbol), &anItem);
506  else
507  aSelection->find(mAddress.appendAddress(itemSymbol), &anItem);
508 
509  if (anItem)
510  anItem->setSelection(NO, YES);
511  }
512 
513  // refresh all namespace handlers (TTExplorer only)
514  aSelection->iterateHandlersSendingMessage(kTTSym_SelectionRefresh);
515 
516  return kTTErrNone;
517  }
518 
519  return kTTErrGeneric;
520 }
521 
522 TTErr TTExplorer::SelectionRefresh()
523 {
524  return returnSelectionBack();
525 }
526 
527 TTErr TTExplorer::FilterSet(const TTValue& inputValue, TTValue& outputValue)
528 {
529  TTDictionaryBasePtr afilter = NULL;
530  TTSymbol filterName, filterKey;
531  TTValue v, filterValue;
532  TTErr err;
533 
534  if (inputValue.size() >= 1)
535  {
536  if (inputValue[0].type() == kTypeSymbol)
537  {
538  filterName = inputValue[0];
539 
540  err = mFilterBank->lookup(filterName, v);
541 
542  // if the filter doesn't exist : create a new one
543  if (err)
544  {
545  afilter = new TTDictionaryBase();
546  afilter->setSchema(kTTSym_filter);
547  mFilterBank->append(filterName, (TTPtr)afilter);
548  }
549  // else get the existing filter and his schema
550  else
551  afilter = TTDictionaryBasePtr((TTPtr)v[0]);
552 
553  // set the keys of the filter
554  for (TTUInt32 i = 1; i < inputValue.size(); i =i+2)
555  {
556 
557  filterKey = inputValue[i];
558  filterValue.copyRange(inputValue, i+1, i+2);
559 
560  if (filterKey == kTTSym_name || filterKey == kTTSym_instance || filterKey == kTTSym_part)
561  {
562  // convert Int32 into symbol for parsing
563  if (filterValue[0].type() == kTypeInt32)
564  {
565  filterValue.toString();
566  TTString instanceString;
567  instanceString = TTString(filterValue[0]);
568  filterValue[0] = TTSymbol(instanceString);
569  }
570  }
571 
572  afilter->append(filterKey, filterValue);
573  }
574  }
575 
576  // append the new filter to the filter list
577  if (afilter) {
578  mFilterList->appendUnique(filterName);
579  return kTTErrNone;
580  }
581  }
582 
583  return kTTErrGeneric;
584 }
585 
586 TTErr TTExplorer::FilterRemove(const TTValue& inputValue, TTValue& outputValue)
587 {
588  TTDictionaryBasePtr afilter;
589  TTSymbol filterName;
590  TTValue v, filterValue;
591  TTErr err;
592 
593  if (inputValue.size() == 1) {
594 
595  if (inputValue[0].type() == kTypeSymbol) {
596 
597  filterName = inputValue[0];
598 
599  err = mFilterBank->lookup(filterName, v);
600 
601  // if the filter exists
602  if (!err) {
603 
604  // remove the filter from the global table
605  mFilterBank->remove(filterName);
606 
607  // delete the filter
608  afilter = TTDictionaryBasePtr((TTPtr)v[0]);
609  delete afilter;
610  }
611 
612  // remove the filter from the filter list
613  mFilterList->remove(filterName);
614 
615  return kTTErrNone;
616  }
617  }
618  // remove all filters from the bank
619  else
620  {
621  for (mFilterList->begin(); mFilterList->end(); mFilterList->next())
622  {
623  filterName = mFilterList->current()[0];
624  mFilterBank->remove(filterName);
625  }
626 
627  delete mFilterList;
628  mFilterList = new TTList();
629  }
630 
631  return kTTErrGeneric;
632 }
633 
634 TTErr TTExplorer::FilterInfo(const TTValue& inputValue, TTValue& outputValue)
635 {
636  TTDictionaryBasePtr aFilter;
637  TTSymbol filterName, key;
638  TTValue v, filterKeys, filterValue;
639  TTErr err;
640 
641  if (inputValue.size() == 1) {
642 
643  if (inputValue[0].type() == kTypeSymbol) {
644 
645  filterName = inputValue[0];
646 
647  err = mFilterBank->lookup(filterName, v);
648 
649  // if the filter exists
650  if (!err) {
651 
652  outputValue.append(filterName);
653 
654  // get the filter
655  aFilter = TTDictionaryBasePtr((TTPtr)v[0]);
656 
657  // get all keys
658  aFilter->getKeys(filterKeys);
659 
660  // for all key, get the value
661  for (TTUInt8 i = 0; i < filterKeys.size(); i++) {
662 
663  key = filterKeys[i];
664  aFilter->lookup(key, filterValue);
665 
666  outputValue.append(key);
667  outputValue.append(filterValue);
668  }
669  }
670 
671  return err;
672  }
673  }
674 
675  return kTTErrGeneric;
676 }
677 
678 TTErr TTExplorer::getFilterList(TTValue& value)
679 {
680  TTSymbol filterName;
681  value.clear();
682 
683  for (mFilterList->begin(); mFilterList->end(); mFilterList->next())
684  {
685  filterName = mFilterList->current()[0];
686  value.append(filterName);
687  }
688 
689  return kTTErrNone;
690 }
691 
692 TTErr TTExplorer::setFilterList(const TTValue& value)
693 {
694  TTSymbol filterName;
695  TTUInt32 i;
696  TTValue v;
697  TTBoolean anError = NO;
698  TTErr err = kTTErrNone;
699 
700  mFilterList->clear();
701 
702  for (i = 0; i < value.size(); i++)
703  {
704  filterName = value[i];
705 
706  err = mFilterBank->lookup(filterName, v);
707 
708  if (!err)
709  mFilterList->append(filterName);
710  else anError = YES;
711  }
712 
713  if (anError) return kTTErrValueNotFound;
714  else return kTTErrNone;
715 }
716 
717 /** */
718 TTErr TTExplorer::returnResultBack()
719 {
720  TTValue keys, result;
721  TTAddressItemPtr aSelection, anItem;
722  TTAddress relativeAddress;
723  TTSymbol newName, lastName = kTTSymEmpty;
724  TTUInt32 i, j;
725  TTBoolean found;
726 
727  // Return the value result back
728  if (mReturnValueCallback.valid()) {
729 
730  // sort keys if needed
731  if (mSort == kTTSym_alphabetic)
732  mResult->getKeysSorted(keys);
733 
734  else if (mSort == kTTSym_priority)
736 
737  // children case : keep only the name part and filter repetitions
738  if (mOutput == kTTSym_children) {
739 
740  for (i = 0; i < keys.size(); i++) {
741 
742  relativeAddress = keys[i];
743  newName = relativeAddress.getName();
744 
745  // filter repetitions
746  found = false;
747  for (j = 0; j < result.size(); j++) {
748  lastName = result[j];
749  if (newName == lastName) {
750  found = true;
751  break;
752  }
753  }
754 
755  if (found)
756  continue;
757 
758  result.append(newName);
759  }
760  }
761 
762  // brothers case : keep only instance part
763  else if (mOutput == kTTSym_brothers) {
764 
765  for (i = 0; i < keys.size(); i++) {
766 
767  relativeAddress = keys[i];
768  result.append(relativeAddress.getInstance());
769  }
770  }
771 
772  // any other case
773  else
774  result = keys;
775 
776  // filter repetitions of a same result (but output empty result)
777  if (!(result == mLastResult) || result.empty()) {
778 
779  // update namespace
780  aSelection = TTModularSelectionLookup(mNamespace);
781  if (aSelection) {
782 
783  // append mAddress to the namespace
784  // and go to mAddress namespace item
785  if (aSelection->find(mAddress, &aSelection) == kTTErrValueNotFound) {
786 
787  aSelection->append(mAddress, &aSelection);
788  aSelection->setSelection(YES, YES);
789  }
790 
791  // in brother case : go to the parent namespace item
792  if (mOutput == kTTSym_brothers)
793  aSelection = aSelection->getParent();
794 
795  // append the result to the namespace
796  for (i = 0; i < result.size(); i++) {
797 
798  relativeAddress = result[i];
799 
800  // append relativeAddress to the namespace
801  if (aSelection->find(relativeAddress, &anItem) == kTTErrValueNotFound) {
802 
803  aSelection->append(relativeAddress, &anItem);
804  anItem->setSelection(YES, YES);
805  }
806  }
807  }
808  TTValue dummy;
809 
810 
811  mLastResult = result;
812  mReturnValueCallback.send("notify", result, dummy);
813 
814  returnSelectionBack();
815  }
816  }
817 
818  return kTTErrNone;
819 }
820 
821 TTErr TTExplorer::returnSelectionBack()
822 {
823  TTAddressItemPtr aSelection = TTModularSelectionLookup(mNamespace);
824  TTAddressItemPtr anItem;
825  TTAddress itemSymbol;
826  TTValue selection;
827  TTInt32 i;
828 
829  if (aSelection) {
830 
831  // return all selection state
832  for (i = 0; i < (TTInt32) mLastResult.size(); i++) {
833 
834  itemSymbol = mLastResult[i];
835 
836  // get the item
837  if (mOutput == kTTSym_children) {
838  aSelection->find(mAddress.appendAddress(itemSymbol), &anItem);
839  anItem = anItem->getParent();
840  }
841  else if (mOutput == kTTSym_brothers)
842  aSelection->find(mAddress.appendInstance(itemSymbol), &anItem);
843 
844  else if (itemSymbol.getType() == kAddressRelative)
845  aSelection->find(mAddress.appendAddress(itemSymbol), &anItem);
846 
847  else
848  aSelection->find(itemSymbol, &anItem);
849 
850  if (anItem)
851  selection.append(anItem->getSelection());
852  }
853  TTValue dummy;
854 
855 
856  return mReturnSelectionCallback.send("notify", selection, dummy);
857  }
858 
859  return kTTErrGeneric;
860 }
861 
862 #if 0
863 #pragma mark -
864 #pragma mark Some Methods
865 #endif
866 
868 {
869  TTValue keys;
870  TTValue t, v;
871  TTObject o, anObserver;
872  TTExplorerPtr anExplorer;
873  TTAddress anAddress, relativeAddress;
874  TTSymbol key;
875  TTNodePtr aNode;
876  TTUInt8 flag;
877 
878  // Unpack baton (#TTExplorerPtr)
879  anExplorer = TTExplorerPtr((TTPtr)baton[0]); // théo -- we have to register our self as a #TTPtr to not reference this instance otherwhise the destructor will never be called
880 
881  // Unpack data (anAddress, aNode, flag, anObserver)
882  anAddress = data[0];
883  aNode = TTNodePtr((TTPtr)data[1]);
884  flag = data[2];
885  anObserver = data[3];
886 
887  // get attributes names
888  if (anExplorer->mOutput == kTTSym_attributes) {
889  if (aNode == anExplorer->mTempNode) {
890 
891  // always clear the result
892  anExplorer->mResult->clear();
893 
894  o = aNode->getObject();
895  if (o.valid())
896  o.attributes(keys);
897  }
898  }
899 
900  // get relative address of nodes matching filter
901  else {
902 
903  // children case and brothers : check parent
904  if (anExplorer->mOutput == kTTSym_children || anExplorer->mOutput == kTTSym_brothers)
905  if (aNode->getParent() != anExplorer->mTempNode)
906  return kTTErrGeneric;
907 
908  TTValue args = TTValue((TTPtr)anExplorer->mFilterBank);
909  args.append((TTPtr)anExplorer->mFilterList);
910 
911  // test the node or add any destroyed node (because sometimes the object can be destroyed before his address)
912  if (testNodeUsingFilter(aNode, (TTPtr)&args) || flag == kAddressDestroyed) {
913 
914  // brothers case : store only the relative address for node with the same name
915  if (anExplorer->mOutput == kTTSym_brothers) {
916  aNode->getAddress(relativeAddress, anExplorer->mAddress.getParent());
917 
918  if (anExplorer->mAddress.getName() == relativeAddress.getName())
919  keys.append(relativeAddress);
920  }
921  else {
922 
923  /*if (anExplorer->mAddress == kTTAdrsRoot)
924  aNode->getAddress(&relativeAddress);
925  else*/
926  aNode->getAddress(relativeAddress, anExplorer->mAddress);
927 
928  keys.append(relativeAddress);
929  }
930 
931  // prepare to store the node with the relativeAddress
932  v.append(TTPtr(aNode));
933  }
934  }
935 
936  if (keys.empty())
937  return kTTErrGeneric;
938 
939  // Add or remove names depending on
940  // if the node is created or destroyed
941  switch (flag) {
942 
943  case kAddressCreated :
944  {
945  for (TTUInt32 i = 0; i < keys.size(); i++) {
946  key = keys[i];
947  anExplorer->mResult->append(key, v);
948  }
949  break;
950  }
951 
952  case kAddressDestroyed :
953  {
954  for (TTUInt32 i = 0; i < keys.size(); i++) {
955  key = keys[i];
956  anExplorer->mResult->remove(key);
957  }
958  break;
959  }
960 
961  default :
962  break;
963  }
964 
965  return anExplorer->returnResultBack();
966 }
967 
969 {
970  TTExplorerPtr anExplorer;
971  TTSymbol anApplicationName;
972  TTObject anApplication;
973  TTValue v;
974  TTUInt8 flag;
975 
976  // Unpack baton (#TTExplorerPtr)
977  anExplorer = TTExplorerPtr((TTPtr)baton[0]); // théo -- we have to register our self as a #TTPtr to not reference this instance otherwhise the destructor will never be called
978 
979  // Unpack data (applicationName, application, flag, observer)
980  anApplicationName = data[0];
981  anApplication = data[1];
982  flag = data[2];
983 
984  switch (flag) {
985 
987  {
988  anExplorer->mDirectory = accessApplicationDirectoryFrom(anExplorer->mAddress);
989  anExplorer->bindAddress();
990  break;
991  }
992 
994  {
995  anExplorer->Explore();
996  break;
997  }
998 
1000  {
1001  break;
1002  }
1003 
1004  case kApplicationReleased :
1005  {
1006  anExplorer->unbindAddress();
1007  break;
1008  }
1009 
1010  default:
1011  break;
1012  }
1013 
1014  return kTTErrNone;
1015 }
1016 
1018 {
1019  TTNodePtr n1, n2;
1020  TTObject o1, o2;
1021  TTValue v;
1022  TTInt32 p1 = 0;
1023  TTInt32 p2 = 0;
1024 
1025  // get priority of v1
1026  n1 = TTNodePtr((TTPtr)v1[1]);
1027  if (n1) {
1028  o1 = n1->getObject();
1029 
1030  if (o1.valid())
1031  if (!o1.get(kTTSym_priority, v))
1032  p1 = v[0];
1033  }
1034 
1035  // get priority of v2
1036  n2 = TTNodePtr((TTPtr)v2[1]);
1037  if (n2) {
1038  o2 = n2->getObject();
1039 
1040  if (o2.valid())
1041  if (!o2.get(kTTSym_priority, v))
1042  p2 = v[0];
1043  }
1044 
1045  if (p1 == 0 && p2 == 0) return v1 < v2;
1046 
1047  if (p1 == 0) return NO;
1048  if (p2 == 0) return YES;
1049 
1050  return p1 < p2;
1051 }
TTAddress appendAddress(const TTAddress &toAppend)
Return a new TTAddress with the appended part.
Definition: TTAddress.h:167
TTErr setSchema(const TTSymbol schemaName)
TODO: Add documentation schemaName TODO: Add documentation.
TTErr(TTObjectBase::* TTSetterMethod)(const TTAttribute &attribute, const TTValue &value)
A type that can be used to store a pointer to a message for an object.
Definition: TTObjectBase.h:78
TTExplorer ...
Definition: TTExplorer.h:28
an application have been released by the application manager
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
#define accessApplicationDirectoryFrom(anAddress)
Access to an application directory using an address.
TTDictionaryBase * TTDictionaryBasePtr
Pointer to a TTDictionary.
this flag means that a TTNode have been destroyed in the tree structure
Definition: TTAddressBase.h:56
TTErr send(const TTSymbol aName)
Send a message to this object with no arguments.
Definition: TTObject.cpp:135
TTSymbol & getInstance()
Get the instance part.
Definition: TTAddress.h:124
TTErr getKeysSorted(TTValue &hashKeysSorted, TTBoolean(*comparisonFunction)(TTValue &, TTValue &)=NULL)
Get an array of all of the keys sorted for the hash table.
Definition: TTHash.cpp:148
friend TTErr TTMODULAR_EXPORT TTExplorerApplicationManagerCallback(const TTValue &baton, const TTValue &data)
Definition: TTExplorer.cpp:968
TTErr TTExplorerApplicationManagerCallback(const TTValue &baton, const TTValue &data)
Definition: TTExplorer.cpp:968
TTString toString(TTBoolean quotes=YES) const
Return the content as a single string with spaces between elements.
Definition: TTValue.h:351
TTErr lookup(const TTSymbol key, TTValue &value)
Find the value for the given key.
Definition: TTHash.cpp:76
TTSymbol & getDirectory()
Get the directory part.
Definition: TTAddress.h:106
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
Definition: TTNode.h:59
A type that contains a key and a value.
application's protocol will be stopped
8-bit unsigned integer, range is 0 through 255.
Definition: TTBase.h:274
TTAddress getParent()
Get a pointer to the parent address.
Definition: TTAddress.h:112
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Definition: TTAddress.h:29
Create and use Jamoma object instances.
Definition: TTObject.h:29
TTObject & getObject()
Get the object binded by this node.
Definition: TTNode.cpp:468
size_type size() const noexcept
Return the number of elements.
TTAddressItemPtr TTMODULAR_EXPORT TTModularSelectionLookup(const TTSymbol selectionName)
Get a selection or create one if it doesn't exist yet.
Definition: TTModular.cpp:110
TTAddress appendInstance(const TTSymbol anInstance)
Return a new TTAddress with a instance part.
Definition: TTAddress.h:173
this flag means that an address have no leading slash
Definition: TTAddressBase.h:64
Maintain a collection of TTValue objects indexed by TTSymbol pointers.
Definition: TTHash.h:36
Symbol type.
Definition: TTBase.h:282
TTErr Lookup(TTAddress anAddress, TTList &returnedTTNodes, TTNodePtr *firstReturnedTTNode)
Find TTNodes by address.
This is a special type used by TTAttribute to indicate that a value is a TTValue and is locally maint...
Definition: TTBase.h:286
TTErr TTExplorerDirectoryCallback(const TTValue &baton, const TTValue &data)
Definition: TTExplorer.cpp:867
TTErr TTMODULAR_EXPORT TTApplicationManagerAddApplicationObserver(TTSymbol anApplicationName, const TTObject anObserver)
Add a TTCallback as observer of application creation/destruction note : it uses the extern TTModularA...
TTBoolean TTExplorerCompareNodePriority(TTValue &v1, TTValue &v2)
compare priority attribute of object's node
void append(const T &anElementValueToAppend)
Insert a single TTElement at the end.
Definition: TTValue.h:243
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
TTErr get(const TTSymbol aName, T &aReturnedValue) const
Get an attribute value for an object.
application's protocol have been started
TTErr set(const TTSymbol aName, T aValue)
Set an attribute value for an object.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTErr append(const TTSymbol key, const TTValue &value)
Insert an item into the hash table.
Definition: TTHash.cpp:70
TTErr addObserverForNotifications(TTAddress anAddress, TTObject &anObserver, TTInt8 maxDepthDifference=-1)
Add a TTCallback as a life cycle observer of all nodes below this one.
Boolean (1/0) or (true/false) flag.
Definition: TTBase.h:281
TTErr TTMODULAR_EXPORT TTApplicationManagerRemoveApplicationObserver(TTSymbol anApplicationName, const TTObject anObserver)
Remove a TTCallback as observer of application creation/destruction note : it uses the extern TTModul...
A value was not found when doing a look up for it (in a TTHash, TTList, or other class).
Definition: TTBase.h:352
this flag means that an address have a leading slash
Definition: TTAddressBase.h:65
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
TTErr lookup(const TTSymbol key, TTValue &value) const
Find the value for the given key.
std::int32_t TTInt32
32 bit signed integer
Definition: TTBase.h:177
TTErr clear()
Remove all items from the hash table.
Definition: TTHash.cpp:117
an application have been intantiated by the application manager
A Namespace Explorer Object.
void clear()
Clear all values from the vector, leaving with size of 0.
Definition: TTValue.h:131
TTErr LookFor(TTListPtr whereToSearch, TTBoolean(*testFunction)(TTNodePtr node, TTPtr args), void *argument, TTList &returnedTTNodes, TTNodePtr *firstReturnedTTNode, TTUInt8 depthLimit=0, TTBoolean(*comparisonFunction)(TTValue &v1, TTValue &v2)=NULL)
Find TTNodes by testing each TTNodes below an address.
TTErr getAddress(TTAddress &returnedAddress, TTAddress from=kTTAdrsEmpty)
Get the address of the node.
Definition: TTNode.cpp:478
32-bit signed integer, range is -2,147,483,648 through 2,147,483,647.
Definition: TTBase.h:277
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
Definition: TTBase.h:344
TTAddressType getType()
Get the type.
Definition: TTAddress.h:136
TTErr remove(const TTSymbol key)
Remove an item from the hash table.
Definition: TTHash.cpp:108
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
friend TTErr TTMODULAR_EXPORT TTExplorerDirectoryCallback(const TTValue &baton, const TTValue &data)
Definition: TTExplorer.cpp:867
TTErr append(const TTSymbol key, const TTValue &value)
Insert an item into the hash table.
this flag means that a TTNode have been created in the tree structure
Definition: TTAddressBase.h:57
TTErr removeObserverForNotifications(TTAddress anAddress, TTObject &anObserver)
Remove a TTCallback as a life cycle observer of all nodes below this one.
void attributes(TTValue &returnedAttributeNames) const
Return a list of names of the available attributes.
Definition: TTObject.cpp:111
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
TTErr remove(const TTSymbol key)
Remove an item from the hash table.
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
No Error.
Definition: TTBase.h:343
void copyRange(const TTValue &obj, TTUInt16 startIndex, TTUInt16 endIndex)
Copy a value starting from an index until another index.
Definition: TTValue.h:138
The TTString class is used to represent a string.
Definition: TTString.h:34
TTBoolean valid() const
Determine if the object contained by this TTObject is truly ready for use.
Definition: TTObject.cpp:179
TTErr(TTObjectBase::* TTGetterMethod)(const TTAttribute &attribute, TTValue &value)
A type that can be used to store a pointer to a message for an object.
Definition: TTObjectBase.h:73
TTSymbol & getName()
Get the name part.
Definition: TTAddress.h:118
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTNodePtr getParent()
Get a pointer to the parent node of the node.
Definition: TTNode.cpp:296
unsigned char TTUInt8
8 bit unsigned integer (char)
Definition: TTBase.h:174
TTErr getKeys(TTValue &hashKeys)
Get an array of all of the keys for the hash table.