aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/xsample/source/main.cpp
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2005-01-08 04:59:44 +0000
committerThomas Grill <xovo@users.sourceforge.net>2005-01-08 04:59:44 +0000
commiteba585829684fcf54a0c8614709d2c10c75032b4 (patch)
tree9f4e2ca184f37852fd5c5d8e30df10b100f25ffd /externals/grill/xsample/source/main.cpp
parent0709ac9fabf4184675df1c3d8e205a2790adaadb (diff)
merge in branch "20041229-unify"
- some small cleanups os x fixes minor updates improved buffer handling simplify updates Mac adaptations - made xcode project preparing xsample 0.3.0 release updated for build system some optimizations - fixed loop record bug Completion of attribute functionality, revisited and updated help files svn path=/trunk/; revision=2477
Diffstat (limited to 'externals/grill/xsample/source/main.cpp')
-rw-r--r--externals/grill/xsample/source/main.cpp244
1 files changed, 118 insertions, 126 deletions
diff --git a/externals/grill/xsample/source/main.cpp b/externals/grill/xsample/source/main.cpp
index 3cec1b66..030c2675 100644
--- a/externals/grill/xsample/source/main.cpp
+++ b/externals/grill/xsample/source/main.cpp
@@ -1,26 +1,25 @@
/*
-
xsample - extended sample objects for Max/MSP and pd (pure data)
-Copyright (c) 2001-2004 Thomas Grill (xovo@gmx.net)
+Copyright (c) 2001-2005 Thomas Grill (gr@grrrr.org)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.
-
*/
#include "main.h"
// Initialization function for xsample library
-static V xsample_main()
+static void xsample_main()
{
flext::post("-------------------------------");
flext::post("xsample objects, version " XSAMPLE_VERSION);
flext::post("");
flext::post(" xrecord~, xplay~, xgroove~ ");
- flext::post(" (C)2001-2004 Thomas Grill ");
+ flext::post(" (C)2001-2005 Thomas Grill ");
#ifdef FLEXT_DEBUG
- flext::post(" DEBUG BUILD ");
+ flext::post("");
+ flext::post("DEBUG BUILD - " __DATE__ " " __TIME__);
#endif
flext::post("-------------------------------");
@@ -37,10 +36,6 @@ FLEXT_LIB_SETUP(xsample,xsample_main)
void xsample::setup(t_classid c)
{
- FLEXT_CADDBANG(c,0,m_start);
- FLEXT_CADDMETHOD_(c,0,"start",m_start);
- FLEXT_CADDMETHOD_(c,0,"stop",m_stop);
-
FLEXT_CADDMETHOD_(c,0,"set",m_set);
FLEXT_CADDMETHOD_(c,0,"print",m_print);
FLEXT_CADDMETHOD_(c,0,"refresh",m_refresh);
@@ -53,163 +48,160 @@ void xsample::setup(t_classid c)
}
xsample::xsample():
- buf(NULL),
+ update(xsc_all),
#if FLEXT_SYS == FLEXT_SYS_MAX
unitmode(xsu_ms), // Max/MSP defaults to milliseconds
#else
unitmode(xsu_sample), // PD defaults to samples
#endif
sclmode(xss_unitsinbuf),
- curmin(0),curmax(1<<31)
+ curmin(0),curmax(1<<(sizeof(curmax)*8-2))
{}
-xsample::~xsample()
+xsample::~xsample() {}
+
+bool xsample::Finalize()
{
-// m_enable(false); // switch off DSP
+ if(!flext_dsp::Finalize()) return false;
- if(buf) delete buf;
+ // flags have been set in constructor
+ Refresh();
+ return true;
}
-
-BL xsample::bufchk()
-{
- if(buf->Valid()) {
- if(buf->Update()) {
-// post("%s - buffer updated",thisName());
- m_refresh();
- }
- return true;
- }
- else
- return false;
+int xsample::ChkBuffer(bool refresh)
+{
+ if(!buf.Ok()) return 0;
+
+ if(buf.Update()) {
+#ifdef FLEXT_DEBUG
+ post("%s - buffer update!",thisName());
+#endif
+ Update(xsc_buffer);
+ if(refresh) {
+ Refresh();
+ return buf.Ok() && buf.Valid()?1:0;
+ }
+ else
+ return buf.Valid()?1:0;
+ }
+ else
+ return buf.Valid()?-1:0;
}
-I xsample::m_set(I argc,const t_atom *argv)
+/* called after all buffer objects have been created in the patch */
+void xsample::m_loadbang()
{
- const t_symbol *sym = argc >= 1?GetASymbol(argv[0]):NULL;
- int r = buf->Set(sym);
- if(sym && r < 0) post("%s - can't find buffer %s",thisName(),GetString(sym));
- return r;
+ ChkBuffer(true);
}
-BL xsample::m_refresh()
+void xsample::m_set(int argc,const t_atom *argv)
{
- BL ret;
- if(buf->Set()) { s_dsp(); ret = true; } // channel count may have changed
- else ret = false;
-
- m_units();
- m_sclmode();
- // realize positions... 2 times bufchk()!!
- m_min((F)curmin*s2u); // also checks pos
- m_max((F)curmax*s2u); // also checks pos
-
- return ret;
+ const t_symbol *sym = argc >= 1?GetASymbol(argv[0]):NULL;
+ int r = buf.Set(sym);
+ if(sym && r < 0)
+ post("%s - can't find buffer %s",thisName(),GetString(sym));
+ Update(xsc_buffer,true);
}
-BL xsample::m_reset()
+void xsample::m_min(float mn)
{
- BL ret;
- if(buf->Set()) { s_dsp(); ret = true; } // channel count may have changed
- else ret = false;
-
- // now... 4 times bufchk()!! \todo get rid of that
- m_units();
- m_sclmode();
- m_min(0);
- m_max(buf->Frames()*s2u);
+ int ret = ChkBuffer(true);
- return ret;
-}
+ if(ret && s2u) {
+ long cmn = CASTINT<long>(mn/s2u+0.5f); // conversion to samples
-V xsample::m_loadbang()
-{
- m_reset();
-}
+ if(cmn < 0)
+ curmin = 0;
+ else if(cmn > curmax)
+ curmin = curmax;
+ else
+ curmin = cmn;
-V xsample::m_units(xs_unit mode)
-{
- if(mode != xsu__) unitmode = mode;
-
- switch(unitmode) {
- case xsu_sample: // samples
- s2u = 1;
- break;
- case xsu_buffer: // buffer size
- s2u = bufchk()?1.f/buf->Frames():0;
- break;
- case xsu_ms: // ms
- s2u = 1000.f/Samplerate();
- break;
- case xsu_s: // s
- s2u = 1.f/Samplerate();
- break;
- default:
- post("%s: Unknown unit mode",thisName());
+ Update(xsc_range,true);
}
}
-V xsample::m_sclmode(xs_sclmd mode)
+void xsample::m_max(float mx)
{
- if(mode != xss__) sclmode = mode;
-
- switch(sclmode) {
- case 0: // samples/units
- sclmin = 0; sclmul = s2u;
- break;
- case 1: // samples/units from recmin to recmax
- sclmin = curmin; sclmul = s2u;
- break;
- case 2: // unity between 0 and buffer size
- sclmin = 0; sclmul = (bufchk() && buf->Frames())?1.f/buf->Frames():0;
- break;
- case 3: // unity between recmin and recmax
- sclmin = curmin; sclmul = curmin != curmax?1.f/(curmax-curmin):0;
- break;
- default:
- post("%s: Unknown scale mode",thisName());
- }
-}
+ int ret = ChkBuffer(true);
-V xsample::m_min(F mn)
-{
-// if(!bufchk()) return; // if invalid do nothing (actually, it should be delayed)
+ if(ret && s2u) {
+ long cmx = CASTINT<long>(mx/s2u+0.5f); // conversion to samples
- if(s2u) {
- mn /= s2u; // conversion to samples
- if(mn < 0) mn = 0;
- else if(mn > curmax) mn = (F)curmax;
- curmin = (I)(mn+.5);
+ if(cmx > buf.Frames())
+ curmax = buf.Frames();
+ else if(cmx < curmin)
+ curmax = curmin;
+ else
+ curmax = cmx;
- m_sclmode();
+ Update(xsc_range,true);
}
}
-V xsample::m_max(F mx)
+void xsample::m_dsp(int /*n*/,t_sample *const * /*insigs*/,t_sample *const * /*outsigs*/)
{
-// if(!bufchk()) return; // if invalid do nothing (actually, it should be delayed)
+ // this is hopefully called at change of sample rate ?!
- if(s2u) {
- mx /= s2u; // conversion to samples
- if(mx > buf->Frames()) mx = (F)buf->Frames();
- else if(mx < curmin) mx = (F)curmin;
- curmax = (I)(mx+.5);
+#ifdef FLEXT_DEBUG
+ post("%s - DSP reset!",thisName());
+#endif
- m_sclmode();
- }
+ // for PD at least this is also called if a table has been deleted...
+ // then we must reset the buffer
+
+ Update(xsc_srate|xsc_buffer,true);
}
-V xsample::m_all()
+void xsample::DoReset()
{
- if(!bufchk()) return; // if invalid do nothing (actually, it should be delayed)
-
- curmin = 0; curmax = buf->Frames();
- m_sclmode();
+ ResetRange();
}
-V xsample::m_dsp(I /*n*/,S *const * /*insigs*/,S *const * /*outsigs*/)
+void xsample::DoUpdate(unsigned int flags)
{
- // this is hopefully called at change of sample rate ?!
-
- if(!m_refresh()) s_dsp();
+ if(flags&xsc_buffer)
+ buf.Set();
+
+ if(flags&xsc_range && buf.Ok()) {
+ if(curmin < 0) curmin = 0;
+ if(curmax > buf.Frames()) curmax = buf.Frames();
+ }
+
+ if(flags&xsc_units) {
+ switch(unitmode) {
+ case xsu_sample: // samples
+ s2u = 1;
+ break;
+ case xsu_buffer: // buffer size
+ s2u = buf.Ok() && buf.Frames()?1.f/buf.Frames():0;
+ break;
+ case xsu_ms: // ms
+ s2u = 1000.f/Samplerate();
+ break;
+ case xsu_s: // s
+ s2u = 1.f/Samplerate();
+ break;
+ default:
+ post("%s - Unknown unit mode",thisName());
+ }
+
+ switch(sclmode) {
+ case xss_unitsinbuf: // samples/units
+ sclmin = 0; sclmul = s2u;
+ break;
+ case xss_unitsinloop: // samples/units from recmin to recmax
+ sclmin = curmin; sclmul = s2u;
+ break;
+ case xss_buffer: // unity between 0 and buffer size
+ sclmin = 0; sclmul = buf.Ok() && buf.Frames()?1.f/buf.Frames():0;
+ break;
+ case xss_loop: // unity between recmin and recmax
+ sclmin = curmin; sclmul = curmin < curmax?1.f/(curmax-curmin):0;
+ break;
+ default:
+ post("%s - Unknown scale mode",thisName());
+ }
+ }
}