<div dir="ltr"><div>Thank you Michael, Ermina and Jean!</div><div>It is working a treat.</div><div><br></div><div>Micheal<br></div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 21 Jan 2020 at 17:00, &lt;<a href="mailto:chuck-users-request@lists.cs.princeton.edu">chuck-users-request@lists.cs.princeton.edu</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Send chuck-users mailing list submissions to<br>
        <a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
or, via email, send a message with subject or body &#39;help&#39; to<br>
        <a href="mailto:chuck-users-request@lists.cs.princeton.edu" target="_blank">chuck-users-request@lists.cs.princeton.edu</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:chuck-users-owner@lists.cs.princeton.edu" target="_blank">chuck-users-owner@lists.cs.princeton.edu</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of chuck-users digest...&quot;<br>
Today&#39;s Topics:<br>
<br>
   1. Conversion float to int using SndBuf (M?che?l ? Cath?in)<br>
   2. Re: Conversion float to int using SndBuf (Michael Heuer)<br>
   3. Re: Conversion float to int using SndBuf (ermina)<br>
   4. Re: Conversion float to int using SndBuf (Jean Menezes da Rocha)<br>
<br><br><br>---------- Forwarded message ----------<br>From: &quot;Mícheál Ó Catháin&quot; &lt;<a href="mailto:micheal.ocathain@gmail.com" target="_blank">micheal.ocathain@gmail.com</a>&gt;<br>To: <a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>Cc: <br>Bcc: <br>Date: Tue, 21 Jan 2020 13:08:02 +0000<br>Subject: [chuck-users] Conversion float to int using SndBuf<br><div dir="ltr"><div>Hi</div><div>What is the best way to convert a float to int in the following please?</div><div><br></div><div>//I want to set myBuf.pos to a percentage of myBuf.samples()...</div><div>//Start playing at say 40% through the total number of samples.</div><div><br></div><div>40.0 =&gt; float pctPosInit;</div><div>pctPosInit/100*myBuf.samples() =&gt; myBuf.pos;</div><div><br></div><div><br></div><div>This throws the error argument types don&#39;t match. <br></div><div>I&#39;m not seeing how to convert the float to an int here.</div><div>Thanks for your help!</div><div><br></div><div>Micheal<br></div></div>
<br><br><br>---------- Forwarded message ----------<br>From: Michael Heuer &lt;<a href="mailto:heuermh@gmail.com" target="_blank">heuermh@gmail.com</a>&gt;<br>To: ChucK Users Mailing List &lt;<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a>&gt;<br>Cc: <br>Bcc: <br>Date: Tue, 21 Jan 2020 09:35:12 -0600<br>Subject: Re: [chuck-users] Conversion float to int using SndBuf<br>Hello Mícheál,<br>
<br>
The ChucK language has a cast operator &#39;$&#39; which might come in handy in this situation<br>
<br>
(pctPosInit/100*myBuf.samples()) $ int =&gt; myBuf.pos;<br>
<br>
Cheers,<br>
<br>
   michael<br>
<br>
<br>
&gt; On Jan 21, 2020, at 7:08 AM, Mícheál Ó Catháin &lt;<a href="mailto:micheal.ocathain@gmail.com" target="_blank">micheal.ocathain@gmail.com</a>&gt; wrote:<br>
&gt; <br>
&gt; Hi<br>
&gt; What is the best way to convert a float to int in the following please?<br>
&gt; <br>
&gt; //I want to set myBuf.pos to a percentage of myBuf.samples()...<br>
&gt; //Start playing at say 40% through the total number of samples.<br>
&gt; <br>
&gt; 40.0 =&gt; float pctPosInit;<br>
&gt; pctPosInit/100*myBuf.samples() =&gt; myBuf.pos;<br>
&gt; <br>
&gt; <br>
&gt; This throws the error argument types don&#39;t match. <br>
&gt; I&#39;m not seeing how to convert the float to an int here.<br>
&gt; Thanks for your help!<br>
&gt; <br>
&gt; Micheal<br>
&gt; _______________________________________________<br>
&gt; chuck-users mailing list<br>
&gt; <a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
&gt; <a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
<br>
<br>
<br><br><br>---------- Forwarded message ----------<br>From: ermina &lt;<a href="mailto:ermina@studioplume.com" target="_blank">ermina@studioplume.com</a>&gt;<br>To: <a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>Cc: <br>Bcc: <br>Date: Tue, 21 Jan 2020 16:47:40 +0100<br>Subject: Re: [chuck-users] Conversion float to int using SndBuf<br>Hi,<br>
<br>
to convert a float to an int,<br>
you need to explicitly cast the value with<br>
4.8 $ int =&gt; int foo;  // foo == 4<br>
(as written here: <a href="https://chuck.cs.princeton.edu/doc/language/oper.html" rel="noreferrer" target="_blank">https://chuck.cs.princeton.edu/doc/language/oper.html</a>)<br>
<br>
So you would do something like<br>
pctPosInit $ int =&gt; int pctPosInitInt<br>
pctPosInitInt/100*myBuf.samples() =&gt; myBuf.pos;<br>
<br>
. e<br>
On 01/21/2020 02:08 PM, Mícheál Ó Catháin wrote:<br>
&gt; Hi<br>
&gt; What is the best way to convert a float to int in the following please?<br>
&gt; <br>
&gt; //I want to set myBuf.pos to a percentage of myBuf.samples()...<br>
&gt; //Start playing at say 40% through the total number of samples.<br>
&gt; <br>
&gt; 40.0 =&gt; float pctPosInit;<br>
&gt; pctPosInit/100*myBuf.samples() =&gt; myBuf.pos;<br>
&gt; <br>
&gt; <br>
&gt; This throws the error argument types don&#39;t match.<br>
&gt; I&#39;m not seeing how to convert the float to an int here.<br>
&gt; Thanks for your help!<br>
&gt; <br>
&gt; Micheal<br>
&gt; <br>
&gt; <br>
&gt; _______________________________________________<br>
&gt; chuck-users mailing list<br>
&gt; <a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
&gt; <a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
&gt; <br>
<br>
<br><br><br>---------- Forwarded message ----------<br>From: Jean Menezes da Rocha &lt;<a href="mailto:jean@menezesdarocha.info" target="_blank">jean@menezesdarocha.info</a>&gt;<br>To: ChucK Users Mailing List &lt;<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a>&gt;<br>Cc: <br>Bcc: <br>Date: Tue, 21 Jan 2020 12:58:36 -0300<br>Subject: Re: [chuck-users] Conversion float to int using SndBuf<br><div dir="ltr">I would suggest that you call Math.round() before casting, as to prevent undesirable effects: notice that in the example sent by ermina, 4.8 rounds down to 4 when cast to int, which could cause miscalculations <b>depending on your use case</b>.<div>The previous example would look something like this if we used Math.round():</div><div><br></div><div><font face="monospace">Math.round(pctPosInit) $ int =&gt; int pctPosInitInt;</font></div><div><font face="monospace">pctPosInitInt/100*myBuf.samples() =&gt; myBuf.pos;</font></div><div><br></div><div>Best regards!</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 21, 2020 at 12:49 PM ermina &lt;<a href="mailto:ermina@studioplume.com" target="_blank">ermina@studioplume.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
to convert a float to an int,<br>
you need to explicitly cast the value with<br>
4.8 $ int =&gt; int foo;  // foo == 4<br>
(as written here: <a href="https://chuck.cs.princeton.edu/doc/language/oper.html" rel="noreferrer" target="_blank">https://chuck.cs.princeton.edu/doc/language/oper.html</a>)<br>
<br>
So you would do something like<br>
pctPosInit $ int =&gt; int pctPosInitInt<br>
pctPosInitInt/100*myBuf.samples() =&gt; myBuf.pos;<br>
<br>
. e<br>
On 01/21/2020 02:08 PM, Mícheál Ó Catháin wrote:<br>
&gt; Hi<br>
&gt; What is the best way to convert a float to int in the following please?<br>
&gt; <br>
&gt; //I want to set myBuf.pos to a percentage of myBuf.samples()...<br>
&gt; //Start playing at say 40% through the total number of samples.<br>
&gt; <br>
&gt; 40.0 =&gt; float pctPosInit;<br>
&gt; pctPosInit/100*myBuf.samples() =&gt; myBuf.pos;<br>
&gt; <br>
&gt; <br>
&gt; This throws the error argument types don&#39;t match.<br>
&gt; I&#39;m not seeing how to convert the float to an int here.<br>
&gt; Thanks for your help!<br>
&gt; <br>
&gt; Micheal<br>
&gt; <br>
&gt; <br>
&gt; _______________________________________________<br>
&gt; chuck-users mailing list<br>
&gt; <a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
&gt; <a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
&gt; <br>
_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><span style="color:rgb(136,136,136)">Jean Menezes da Rocha</span><br></div></div></div></div>
_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
</blockquote></div></div>