<?xml version="1.0" encoding="UTF-8"?>
	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:atom="http://www.w3.org/2005/Atom"

			>

	<channel>
		<title>Cycling 74  &#187;  Topic: enumindex with custom get/set</title>
		<atom:link href="http://cycling74.com/forums/topic/enumindex-with-custom-getset/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/enumindex-with-custom-getset/feed</link>
		<description></description>
		<pubDate>Wed, 19 Jun 2013 13:22:56 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-54846</guid>
					<title><![CDATA[enumindex with custom get/set]]></title>
					<link>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-54846</link>
					<pubDate>Tue, 08 Feb 2011 07:30:26 +0000</pubDate>
					<dc:creator>Luigi Castelli</dc:creator>

					<description>
						<![CDATA[
						<p>Hi there,</p>
<p>I have declared an attribute as such:</p>
<pre><code>CLASS_ATTR_LONG(c,      	"myattr", 	0, t_myobj, myattr);
CLASS_ATTR_ACCESSORS(c,		"myattr",    	(method)myobj_myattr_get, (method)myobj_myattr_set);
CLASS_ATTR_ENUMINDEX(c,		"myattr",	0, "Left Center Right");
CLASS_ATTR_DEFAULT_SAVE_PAINT(c,"myattr",    	0, "0");</code></pre><p>The custom getter and setter:</p>
<pre><code>t_max_err myobj_myattr_get(t_myobj *x, t_object *attr, long *argc, t_atom **argv)
{
    char alloc;

    if (argc &#038;&#038; argv) {
	if (atom_alloc(argc, argv, &#038;alloc)) {
            return MAX_ERR_OUT_OF_MEM;
        }
        if (alloc) {
            atom_setlong(*argv, x->myattr);
	}
    }
    return MAX_ERR_NONE;
}

t_max_err myobj_myattr_set(t_myobj *x, t_object *attr, long argc, t_atom *argv)
{
    if (argc &#038;&#038; argv) {
        x->myattr = atom_getlong(argv);
    }
    return MAX_ERR_NONE;
}</code></pre><p>Pretty straightforward, however I have one problem:<br />
if I understand everything clearly, the CLASS_ATTR_ENUMINDEX macro creates an &#8220;enumindex&#8221; attribute, which becomes an attribute of the &#8220;myattr&#8221; attribute.<br />
However it seems I am having problems updating the &#8220;enumindex&#8221; attribute when I use a custom getter and setter.</p>
<p>In other words, when the user clicks on an inlet of my object and the quickref menu gets displayed, the string portion of &#8220;myattr&#8221; always says &#8220;Left&#8221; even though the numeric value associated with &#8220;myattr&#8221; might change. I also see a &#8216;bad number&#8217; error in the Max window.</p>
<p>So I am guessing that there must be a way to update the &#8220;enumindex&#8221; attribute after changing the value of myattr in order for the two to be synced together.<br />
Probably I need to do it manually since I defeat the internal setter and getter. But how ???</p>
<p>Any suggestions ?</p>
<p>Thanks.</p>
<p>- Luigi</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197506</guid>
					<title><![CDATA[Re: enumindex with custom get/set]]></title>
					<link>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197506</link>
					<pubDate>Tue, 08 Feb 2011 09:19:04 +0000</pubDate>
					<dc:creator>Emmanuel Jourdan</dc:creator>

					<description>
						<![CDATA[
						<p>Unless I didn&#8217;t read properly, you shouldn&#8217;t need to have a custom gettr, so the following should work.</p>
<pre><code>CLASS_ATTR_ACCESSORS(c,		"myattr",    	(method)NULL, (method)myobj_myattr_set);</code></pre><p>In this case it uses the standard gettr method.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197507</guid>
					<title><![CDATA[Re: enumindex with custom get/set]]></title>
					<link>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197507</link>
					<pubDate>Tue, 08 Feb 2011 11:14:55 +0000</pubDate>
					<dc:creator>Luigi Castelli</dc:creator>

					<description>
						<![CDATA[
						<p>I know, but I do need a custom getter&#8230;<br />
how do I make it work with a custom getter ?</p>
<p>- Luigi</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197508</guid>
					<title><![CDATA[Re: enumindex with custom get/set]]></title>
					<link>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197508</link>
					<pubDate>Tue, 08 Feb 2011 16:49:09 +0000</pubDate>
					<dc:creator>nicolas danet</dc:creator>

					<description>
						<![CDATA[
						<p>Hello Luigi Castelli,</p>
<p>i did something like that ; maybe have a look in the sources of my [november] external ;<br />
sorry don&#8217;t have time to make a cleaner example ;-) </p>
<p>HTH</p>
<p>EDIT : oops / not ENUMINDEX in my code but ENUM &#8230;</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197509</guid>
					<title><![CDATA[Re: enumindex with custom get/set]]></title>
					<link>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197509</link>
					<pubDate>Tue, 08 Feb 2011 16:56:57 +0000</pubDate>
					<dc:creator>Emmanuel Jourdan</dc:creator>

					<description>
						<![CDATA[
						<p>it should be something like this. alloc doesn&#8217;t return anything really interesting in this case.</p>
<pre><code>
t_max_err myobj_myattr_get(t_myobj *x, t_object *attr, long *argc, t_atom **argv)
{
    char alloc;

    if (argc &#038;&#038; argv) {
	if (atom_alloc(argc, argv, &#038;alloc)) {
            return MAX_ERR_GENERIC;
        }
        atom_setlong(*argv, x->myattr);
    }
    return MAX_ERR_NONE;
}

</code></pre>						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197510</guid>
					<title><![CDATA[Re: enumindex with custom get/set]]></title>
					<link>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197510</link>
					<pubDate>Wed, 09 Feb 2011 02:44:06 +0000</pubDate>
					<dc:creator>Luigi Castelli</dc:creator>

					<description>
						<![CDATA[
						<p>yes, that&#8217;s what I would think too&#8230;</p>
<p>However the above custom getter produces an &#8220;enumindex: bad number&#8221; error in the Max window and fails to update the symbol portion of the attribute.</p>
<p>Curiously enough, if the same attribute is declared as ENUM (with a symbol datatype) everything works fine.</p>
<p>To better illustrate the problem I wrote a simple UI external with just one attribute defined as ENUMINDEX with custom getter and setter.</p>
<p>If you compile it and then open the help file you will find instructions to reproduce the problem exactly as it appears to me.</p>
<p>Please, let me know what you guys think&#8230;</p>
<p>Thanks a lot.</p>
<p>- Luigi</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197511</guid>
					<title><![CDATA[Re: enumindex with custom get/set]]></title>
					<link>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197511</link>
					<pubDate>Wed, 09 Feb 2011 07:27:31 +0000</pubDate>
					<dc:creator>nicolas danet</dc:creator>

					<description>
						<![CDATA[
						<p>Hello Luigi,</p>
<p>problem comes from <code>if (alloc)</code> statement in you code :</p>
<pre><code>if (alloc) {
atom_setlong(*argv, x->state);
}</code></pre><p>as EJ said ;-)  </p>
<p><code>atom_setlong(*argv, x->state);</code></p>
<p>IMHO, you don&#8217;t need to test <code>alloc</code> as if memory have been passed you get zero, but you still need to set the atom passed ; that seems to happen in your method ; so you get bad number error when you query attributes with the inlet popup window &#8230; </p>
<p>expert opinion ?</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197512</guid>
					<title><![CDATA[Re: enumindex with custom get/set]]></title>
					<link>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197512</link>
					<pubDate>Wed, 09 Feb 2011 09:31:23 +0000</pubDate>
					<dc:creator>Emmanuel Jourdan</dc:creator>

					<description>
						<![CDATA[
						<p>tha alloc is true only when <code>atom_alloc</code> allocates the memory. But if <code>ac &#038;&#038; av</code> that you pass as argument of the method are non <code>NULL</code>, <code>atom_alloc</code> will not allocate memory and use the already allocated memory instead. What you really want to look at to see if the memory is valid is the return value of <code>atom_alloc</code>, if the <code>t_max_err</code> value returned is <code>MAX_ERR_NONE</code> you&#8217;re god to go.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197513</guid>
					<title><![CDATA[Re: enumindex with custom get/set]]></title>
					<link>http://cycling74.com/forums/topic/enumindex-with-custom-getset/#post-197513</link>
					<pubDate>Wed, 09 Feb 2011 11:41:52 +0000</pubDate>
					<dc:creator>Luigi Castelli</dc:creator>

					<description>
						<![CDATA[
						<p>Of course&#8230;. sorry for my silliness&#8230;. it was late at night&#8230;.<br />
Problem is solved exactly like you guys said.</p>
<p>Emmanuel and Vanille, thank you so much for your help.</p>
<p>- Luigi</p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

