19 #define thisTTClass TTExplorer
20 #define thisTTClassName "Explorer"
21 #define thisTTClassTags "explorer"
23 TT_MODULAR_CONSTRUCTOR,
24 mNamespace(kTTSym_none),
25 mAddress(kTTAdrsEmpty),
26 mOutput(kTTSym_descendants),
28 mSort(kTTSym_alphabetic),
35 if(arguments.size() >= 1)
36 mReturnValueCallback = arguments[0];
39 if(arguments.size() >= 2)
42 mFilterBank =
new TTHash();
44 if(arguments.size() >= 3)
45 mReturnSelectionCallback = arguments[2];
68 mFilterList =
new TTList();
72 TTExplorer::~TTExplorer()
84 TTAddressItemPtr aSelection;
91 aSelection->unregisterHandler(thisObject);
100 aSelection->registerHandler(thisObject);
109 if (newOutput == kTTSym_descendants ||
110 newOutput == kTTSym_children ||
111 newOutput == kTTSym_brothers ||
112 newOutput == kTTSym_attributes) {
116 setAddress(mAddress);
134 return bindAddress();
136 return bindApplication();
146 if (mUpdate == oldUpdate)
149 return setAddress(mAddress);
159 if (mSort == oldSort)
162 if (mSort == kTTSym_none || mSort == kTTSym_alphabetic || mSort == kTTSym_priority)
175 if (mDepth == oldDepth)
178 return setAddress(mAddress);
181 TTErr TTExplorer::bindAddress()
187 if (mUpdate && mAddress != kTTAdrsEmpty) {
190 mAddressObserver =
TTObject(
"callback");
192 mAddressObserver.
set(kTTSym_baton,
TTPtr(
this));
207 TTErr TTExplorer::unbindAddress()
210 if (mDirectory && mAddressObserver.
valid() && mAddress != kTTSymEmpty) {
221 TTErr TTExplorer::bindApplication()
223 if (!mApplicationObserver.
valid()) {
225 mApplicationObserver =
TTObject(
"callback");
227 mApplicationObserver.
set(kTTSym_baton,
TTPtr(
this));
236 TTErr TTExplorer::unbindApplication()
240 if (mApplicationObserver.
valid()) {
252 TTErr TTExplorer::Explore()
256 TTList aNodeList, internalFilterList, allObjectNodes;
270 if (mOutput == kTTSym_brothers)
273 err = mDirectory->
Lookup(mAddress, aNodeList, &mTempNode);
283 if (mOutput == kTTSym_attributes) {
292 attributeName = v[i];
293 mResult->
append(attributeName, none);
306 mDirectory->
LookFor(&aNodeList, testNodeUsingFilter, (
TTPtr)&args, allObjectNodes, &aNode, mDepth);
309 for (allObjectNodes.begin(); allObjectNodes.end(); allObjectNodes.next()) {
314 if (mOutput == kTTSym_children){
319 if (relativeAddress.
getParent() != kTTAdrsEmpty)
326 else if (mOutput == kTTSym_brothers) {
331 if (relativeAddress.
getParent() != kTTAdrsEmpty)
353 return returnResultBack();
362 TTAddressItemPtr anItem = NULL;
367 if (aSelection && inputValue.
size()) {
372 itemSymbol = inputValue[0];
375 if (mOutput == kTTSym_children) {
376 aSelection->find(mAddress.
appendAddress(itemSymbol), &anItem);
377 anItem = anItem->getParent();
379 else if (mOutput == kTTSym_brothers)
383 aSelection->find(mAddress.
appendAddress(itemSymbol), &anItem);
386 aSelection->find(itemSymbol, &anItem);
391 if (inputValue.
size() == 2) {
394 state = inputValue[1];
398 state = !anItem->getSelection();
401 anItem->setSelection(state, YES);
404 aSelection->iterateHandlersSendingMessage(kTTSym_SelectionRefresh);
411 else if (inputValue[0].type() ==
kTypeInt32 && inputValue.
size() == mLastResult.
size()) {
414 for (i = 0; i < (
TTInt32) mLastResult.
size(); i++) {
416 itemSymbol = mLastResult[i];
417 number = inputValue[i];
422 if (mOutput == kTTSym_children) {
423 aSelection->find(mAddress.
appendAddress(itemSymbol), &anItem);
424 anItem = anItem->getParent();
426 else if (mOutput == kTTSym_brothers)
430 aSelection->find(mAddress.
appendAddress(itemSymbol), &anItem);
433 anItem->setSelection(state, YES);
437 aSelection->iterateHandlersSendingMessage(kTTSym_SelectionRefresh);
446 TTErr TTExplorer::SelectAll()
449 TTAddressItemPtr anItem;
455 for (i = 0; i < (
TTInt32) mLastResult.
size(); i++) {
457 itemSymbol = mLastResult[i];
460 if (mOutput == kTTSym_children) {
461 aSelection->find(mAddress.
appendAddress(itemSymbol), &anItem);
462 anItem = anItem->getParent();
464 else if (mOutput == kTTSym_brothers)
468 aSelection->find(mAddress.
appendAddress(itemSymbol), &anItem);
471 anItem->setSelection(YES, YES);
475 aSelection->iterateHandlersSendingMessage(kTTSym_SelectionRefresh);
481 return returnSelectionBack();
485 TTErr TTExplorer::SelectNone()
488 TTAddressItemPtr anItem;
495 for (i = 0; i < (
TTInt32) mLastResult.
size(); i++) {
497 itemSymbol = mLastResult[i];
500 if (mOutput == kTTSym_children) {
501 aSelection->find(mAddress.
appendAddress(itemSymbol), &anItem);
502 anItem = anItem->getParent();
504 else if (mOutput == kTTSym_brothers)
507 aSelection->find(mAddress.
appendAddress(itemSymbol), &anItem);
510 anItem->setSelection(NO, YES);
514 aSelection->iterateHandlersSendingMessage(kTTSym_SelectionRefresh);
522 TTErr TTExplorer::SelectionRefresh()
524 return returnSelectionBack();
534 if (inputValue.
size() >= 1)
538 filterName = inputValue[0];
540 err = mFilterBank->
lookup(filterName, v);
557 filterKey = inputValue[i];
558 filterValue.
copyRange(inputValue, i+1, i+2);
560 if (filterKey == kTTSym_name || filterKey == kTTSym_instance || filterKey == kTTSym_part)
567 instanceString =
TTString(filterValue[0]);
568 filterValue[0] =
TTSymbol(instanceString);
572 afilter->
append(filterKey, filterValue);
578 mFilterList->appendUnique(filterName);
593 if (inputValue.
size() == 1) {
597 filterName = inputValue[0];
599 err = mFilterBank->
lookup(filterName, v);
605 mFilterBank->
remove(filterName);
613 mFilterList->
remove(filterName);
621 for (mFilterList->begin(); mFilterList->end(); mFilterList->next())
623 filterName = mFilterList->current()[0];
624 mFilterBank->
remove(filterName);
628 mFilterList =
new TTList();
638 TTValue v, filterKeys, filterValue;
641 if (inputValue.
size() == 1) {
645 filterName = inputValue[0];
647 err = mFilterBank->
lookup(filterName, v);
652 outputValue.
append(filterName);
664 aFilter->
lookup(key, filterValue);
667 outputValue.
append(filterValue);
683 for (mFilterList->begin(); mFilterList->end(); mFilterList->next())
685 filterName = mFilterList->current()[0];
700 mFilterList->clear();
702 for (i = 0; i < value.
size(); i++)
704 filterName = value[i];
706 err = mFilterBank->
lookup(filterName, v);
709 mFilterList->append(filterName);
718 TTErr TTExplorer::returnResultBack()
721 TTAddressItemPtr aSelection, anItem;
723 TTSymbol newName, lastName = kTTSymEmpty;
728 if (mReturnValueCallback.
valid()) {
731 if (mSort == kTTSym_alphabetic)
734 else if (mSort == kTTSym_priority)
738 if (mOutput == kTTSym_children) {
740 for (i = 0; i < keys.
size(); i++) {
742 relativeAddress = keys[i];
743 newName = relativeAddress.
getName();
747 for (j = 0; j < result.
size(); j++) {
748 lastName = result[j];
749 if (newName == lastName) {
763 else if (mOutput == kTTSym_brothers) {
765 for (i = 0; i < keys.
size(); i++) {
767 relativeAddress = keys[i];
777 if (!(result == mLastResult) || result.empty()) {
787 aSelection->append(mAddress, &aSelection);
788 aSelection->setSelection(YES, YES);
792 if (mOutput == kTTSym_brothers)
793 aSelection = aSelection->getParent();
796 for (i = 0; i < result.
size(); i++) {
798 relativeAddress = result[i];
803 aSelection->
append(relativeAddress, &anItem);
804 anItem->setSelection(YES, YES);
811 mLastResult = result;
812 mReturnValueCallback.
send(
"notify", result, dummy);
814 returnSelectionBack();
821 TTErr TTExplorer::returnSelectionBack()
824 TTAddressItemPtr anItem;
832 for (i = 0; i < (
TTInt32) mLastResult.
size(); i++) {
834 itemSymbol = mLastResult[i];
837 if (mOutput == kTTSym_children) {
838 aSelection->find(mAddress.
appendAddress(itemSymbol), &anItem);
839 anItem = anItem->getParent();
841 else if (mOutput == kTTSym_brothers)
845 aSelection->find(mAddress.
appendAddress(itemSymbol), &anItem);
848 aSelection->find(itemSymbol, &anItem);
851 selection.
append(anItem->getSelection());
856 return mReturnSelectionCallback.
send(
"notify", selection, dummy);
864 #pragma mark Some Methods
885 anObserver = data[3];
888 if (anExplorer->mOutput == kTTSym_attributes) {
889 if (aNode == anExplorer->mTempNode) {
892 anExplorer->mResult->
clear();
904 if (anExplorer->mOutput == kTTSym_children || anExplorer->mOutput == kTTSym_brothers)
905 if (aNode->
getParent() != anExplorer->mTempNode)
915 if (anExplorer->mOutput == kTTSym_brothers) {
919 keys.
append(relativeAddress);
926 aNode->
getAddress(relativeAddress, anExplorer->mAddress);
928 keys.
append(relativeAddress);
947 anExplorer->mResult->
append(key, v);
956 anExplorer->mResult->
remove(key);
965 return anExplorer->returnResultBack();
980 anApplicationName = data[0];
981 anApplication = data[1];
989 anExplorer->bindAddress();
995 anExplorer->Explore();
1006 anExplorer->unbindAddress();
1031 if (!o1.
get(kTTSym_priority, v))
1041 if (!o2.
get(kTTSym_priority, v))
1045 if (p1 == 0 && p2 == 0)
return v1 < v2;
1047 if (p1 == 0)
return NO;
1048 if (p2 == 0)
return YES;
TTAddress appendAddress(const TTAddress &toAppend)
Return a new TTAddress with the appended part.
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.
an application have been released by the application manager
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
#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
TTErr send(const TTSymbol aName)
Send a message to this object with no arguments.
TTSymbol & getInstance()
Get the instance part.
TTErr getKeysSorted(TTValue &hashKeysSorted, TTBoolean(*comparisonFunction)(TTValue &, TTValue &)=NULL)
Get an array of all of the keys sorted for the hash table.
friend TTErr TTMODULAR_EXPORT TTExplorerApplicationManagerCallback(const TTValue &baton, const TTValue &data)
TTErr TTExplorerApplicationManagerCallback(const TTValue &baton, const TTValue &data)
TTString toString(TTBoolean quotes=YES) const
Return the content as a single string with spaces between elements.
TTErr lookup(const TTSymbol key, TTValue &value)
Find the value for the given key.
TTSymbol & getDirectory()
Get the directory part.
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
A type that contains a key and a value.
application's protocol will be stopped
8-bit unsigned integer, range is 0 through 255.
TTAddress getParent()
Get a pointer to the parent address.
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Create and use Jamoma object instances.
TTObject & getObject()
Get the object binded by this node.
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.
TTAddress appendInstance(const TTSymbol anInstance)
Return a new TTAddress with a instance part.
this flag means that an address have no leading slash
Maintain a collection of TTValue objects indexed by TTSymbol pointers.
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...
TTErr TTExplorerDirectoryCallback(const TTValue &baton, const TTValue &data)
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.
void * TTPtr
A generic pointer.
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...
TTErr append(const TTSymbol key, const TTValue &value)
Insert an item into the hash table.
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.
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).
this flag means that an address have a leading slash
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
TTErr lookup(const TTSymbol key, TTValue &value) const
Find the value for the given key.
std::int32_t TTInt32
32 bit signed integer
TTErr clear()
Remove all items from the hash table.
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.
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.
32-bit signed integer, range is -2,147,483,648 through 2,147,483,647.
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
TTAddressType getType()
Get the type.
TTErr remove(const TTSymbol key)
Remove an item from the hash table.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
friend TTErr TTMODULAR_EXPORT TTExplorerDirectoryCallback(const TTValue &baton, const TTValue &data)
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
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.
std::uint32_t TTUInt32
32 bit unsigned integer
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...
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
void copyRange(const TTValue &obj, TTUInt16 startIndex, TTUInt16 endIndex)
Copy a value starting from an index until another index.
The TTString class is used to represent a string.
TTBoolean valid() const
Determine if the object contained by this TTObject is truly ready for use.
TTErr(TTObjectBase::* TTGetterMethod)(const TTAttribute &attribute, TTValue &value)
A type that can be used to store a pointer to a message for an object.
TTSymbol & getName()
Get the name part.
[doxygenAppendixC_copyExample]
TTNodePtr getParent()
Get a pointer to the parent node of the node.
unsigned char TTUInt8
8 bit unsigned integer (char)
TTErr getKeys(TTValue &hashKeys)
Get an array of all of the keys for the hash table.