Jamoma API  0.6.0.a19
PureData/source/j.model/TTModelInfo.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup pdLibrary
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 mObject(NULL)
25 {
26  if (arguments.size() == 1)
27  if (arguments[0].type() == kTypePointer)
28  mObject = (t_object*)(TTPtr(arguments[0]));
29 
31  addAttribute(Class, kTypeSymbol);
32 
34  addMessage(InternalOpen);
35  addMessage(HelpOpen);
36  addMessage(ReferenceOpen);
37  addMessage(ReferenceWrite);
38 
39  // cache some attribute for observer notification
40  this->findAttribute(kTTSym_address, &addressAttribute);
41 }
42 
43 
44 TTModelInfo::~TTModelInfo()
45 {
46  ;
47 }
48 
49 TTErr TTModelInfo::setAddress(const TTValue& newValue)
50 {
51  mAddress = newValue[0];
52 
53  // notify address observers
54  addressAttribute->sendNotification(kTTSym_notify, mAddress); // we use kTTSym_notify because we know that observers are TTCallback
55 
56  return kTTErrNone;
57 }
58 
59 void TTModelInfo::setAddressReadOnly(TTBoolean readOnly)
60 {
61  addressAttribute->setreadOnly(readOnly);
62 }
63 
64 TTErr TTModelInfo::Rename(const TTValue& inputValue, TTValue& outputValue)
65 {
67  TTValue v;
68 
69  TTErr err = x->wrappedObject.send("Rename", inputValue, outputValue);
70 
71  x->wrappedObject.get(kTTSym_service, v);
72  TTSymbol service = v[0];
73 
74  //update model address only in j.model case
75  if (!err && service == kTTSym_model) {
76 
77  x->wrappedObject.get(kTTSym_address, v);
78  mAddress = v[0];
79 
80  // notify address observers
81  addressAttribute->sendNotification(kTTSym_notify, mAddress); // we use kTTSym_notify because we know that observers are TTCallback
82  }
83 
84  return err;
85 }
86 
88 {
89  /* TODO rewrite this for Pd
90  t_canvas *p = jamoma_patcher_get(mObject);
91 
92  object_method(p, _sym_vis);
93  */
94  return kTTErrNone;
95 }
96 
98 {
99  // opening the model helpfile
100  if (mClass != kTTSymEmpty) {
101 
102  t_symbol *helpfileName;
103  jamoma_edit_filename(*HelpPatcherFormat, mClass, &helpfileName);
104  // TODO rewrite for PD
105  // classname_openhelp((char*)helpfileName->s_name);
106 
107  return kTTErrNone;
108  }
109 
110  return kTTErrGeneric;
111 }
112 
114 {
115  // opening the model reference
116  if (mClass != kTTSymEmpty) {
117 
118  t_symbol *refpagefileName;
119  jamoma_edit_filename(*RefpageFormat, mClass, &refpagefileName);
120  // TODO there is no refpage viewer in Pd
121  // classname_openrefpage((char*)refpagefileName->s_name);
122 
123  return kTTErrNone;
124  }
125 
126  return kTTErrGeneric;
127 }
128 
130 {
131  object_method(mObject, gensym("reference_write"));
132 
133  return kTTErrNone;
134 }
135 
137 {
138  /*
139  WrappedModularInstancePtr x = (WrappedModularInstancePtr)self;
140  t_object* patcher = jamoma_patcher_get((t_object*)x);
141  long mute;
142  t_atom a[2];
143 
144  // 'setrock' is the message that is used by pcontrol to enable patcher
145  // it was inside former j.in or out. Not sure for what it was used (audio mute maybe...)
146 
147  if (argc && argv)
148  if (atom_gettype(argv) == A_LONG) {
149  mute = atom_getlong(argv);
150  atom_setlong(a+0, !mute);
151  atom_setlong(a+1, 1);
152  object_method(patcher, gensym("setrock"), 2, a);
153  }
154  */
155 
156  return kTTErrGeneric;
157 }
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.
TTErr HelpOpen()
Open the help page.
Symbol type.
Definition: TTBase.h:282
A base class for Jamoma models.
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
#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