Jamoma API  0.6.0.a19
Max/source/j.model/TTModelInfo.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup maxLibrary
4  *
5  * @brief A base class for Jamoma models
6  *
7  * @details
8  *
9  * @authors Théo de la Hogue
10  *
11  * @copyright © 2013, 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 #include "TTModelInfo.h"
17 
18 #define thisTTClass TTModelInfo
19 #define thisTTClassName "ModelInfo"
20 #define thisTTClassTags "model info"
21 
22 TT_MODULAR_CONSTRUCTOR,
23 mClass(kTTSymEmpty)
24 {
25  if (arguments.size() == 1)
26  if (arguments[0].type() == kTypePointer)
27  mObject = (t_object*)(TTPtr(arguments[0]));
28 
30  addAttribute(Class, kTypeSymbol);
31 
33  addMessage(InternalOpen);
34  addMessage(HelpOpen);
35  addMessage(ReferenceOpen);
36  addMessage(ReferenceWrite);
37 
38  // cache some attribute for observer notification
39  this->findAttribute(kTTSym_address, &addressAttribute);
40 }
41 
42 
43 TTModelInfo::~TTModelInfo()
44 {
45  ;
46 }
47 
49 {
50  mAddress = newValue[0];
51 
52  // notify address observers
53  addressAttribute->sendNotification(kTTSym_notify, mAddress); // we use kTTSym_notify because we know that observers are TTCallback
54 
55  return kTTErrNone;
56 }
57 
58 void TTModelInfo::setAddressReadOnly(TTBoolean readOnly)
59 {
60  addressAttribute->setreadOnly(readOnly);
61 }
62 
63 TTErr TTModelInfo::Rename(const TTValue& inputValue, TTValue& outputValue)
64 {
66  TTValue v;
67 
68  TTErr err = x->wrappedObject.send("Rename", inputValue, outputValue);
69 
70  x->wrappedObject.get(kTTSym_service, v);
71  TTSymbol service = v[0];
72 
73  //update model address only in j.model case
74  if (!err && service == kTTSym_model) {
75 
76  x->wrappedObject.get(kTTSym_address, v);
77  mAddress = v[0];
78 
79  // notify address observers
80  addressAttribute->sendNotification(kTTSym_notify, mAddress); // we use kTTSym_notify because we know that observers are TTCallback
81  }
82 
83  return err;
84 }
85 
87 {
88  t_object *p = jamoma_patcher_get(mObject);
89 
90  object_method(p, _sym_vis);
91 
92  return kTTErrNone;
93 }
94 
96 {
97  // opening the model helpfile
98  if (mClass != kTTSymEmpty) {
99 
100  t_symbol *helpfileName;
101  jamoma_edit_filename(*HelpPatcherFormat, mClass, &helpfileName);
102  classname_openhelp((char*)helpfileName->s_name);
103 
104  return kTTErrNone;
105  }
106 
107  return kTTErrGeneric;
108 }
109 
111 {
112  // opening the model reference
113  if (mClass != kTTSymEmpty) {
114 
115  t_symbol *refpagefileName;
116  jamoma_edit_filename(*RefpageFormat, mClass, &refpagefileName);
117  classname_openrefpage((char*)refpagefileName->s_name);
118 
119  return kTTErrNone;
120  }
121 
122  return kTTErrGeneric;
123 }
124 
126 {
127  object_method(mObject, gensym("reference_write"));
128 
129  return kTTErrNone;
130 }
131 
133 {
134  /*
135  WrappedModularInstancePtr x = (WrappedModularInstancePtr)self;
136  t_object* patcher = jamoma_patcher_get((t_object*)x);
137  long mute;
138  t_atom a[2];
139 
140  // 'setrock' is the message that is used by pcontrol to enable patcher
141  // it was inside former j.in or out. Not sure for what it was used (audio mute maybe...)
142 
143  if (argc && argv)
144  if (atom_gettype(argv) == A_LONG) {
145  mute = atom_getlong(argv);
146  atom_setlong(a+0, !mute);
147  atom_setlong(a+1, 1);
148  object_method(patcher, gensym("setrock"), 2, a);
149  }
150  */
151 
152  return kTTErrGeneric;
153 }
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
void JAMOMA_EXPORT jamoma_edit_filename(TTString format, TTSymbol className, t_symbol **returnedFileName)
Edit a file name from a given file format and a class name.
TTErr send(const TTSymbol aName)
Send a message to this object with no arguments.
Definition: TTObject.cpp:135
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:29
TTErr InternalOpen()
Open the internal patcher.
TTErr setreadOnly(const TTValue &newReadOnlyValue)
Set the readOnly property of the attribute, controlling if the attribute value can be changed or not...
TTErr ReferenceOpen()
Open the reference file.
TTErr sendNotification(const TTSymbol name, const TTValue &arguments)
Send a notification.
t_object JAMOMA_EXPORT * jamoma_patcher_get(t_object *obj)
Convenient method to get the patcher easily.
TTErr HelpOpen()
Open the help page.
Symbol type.
Definition: TTBase.h:282
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
TTErr get(const TTSymbol aName, T &aReturnedValue) const
Get an attribute value for an object.
TTErr ReferenceWrite()
Write the reference file.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTErr Rename(const TTValue &inputValue, TTValue &outputValue)
Rename the model.
TTObject wrappedObject
The instance of the Jamoma object we are wrapping.
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
TTErr Mute()
Mute the patcher.
Data Structure for this object.
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
Definition: TTBase.h:344
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTErr setAddress(const TTValue &newValue)
Atribute accessor.
Pointer type.
Definition: TTBase.h:284
A base class for Jamoma models.
#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
WrappedModularInstance * WrappedModularInstancePtr
Pointer to a wrapped instance of our object.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34