Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • jwilkes/purr-data
  • aggraef/purr-data
  • samthursfield/purr-data
  • prakhar/purr-data
  • yadu05/purr-data
  • NegiAkash890/purr-data
  • prateekpardeshi/purr-data
  • Shruti3004/purr-data
  • hidimpu/purr-data
  • Atseosi/purr-data
  • piyushjasaiwal/purr-data
  • deveshprasad/purr-data
  • skm_7/purr-data
  • sankt/purr-data
  • ashim_tom/purr-data
  • dineshsoni02/purr-data
  • chaitanya1-coder/purr-data
  • Nitish0007/purr-data
  • nitin/purr-data
  • shuvam09/purr-data
  • gabrielabittencourt/purr-data
  • sivasai/purr-data
  • flachyjoe/purr-data
  • ishankaler/purr-data
  • prateek/purr-data
  • RukshanJS/purr-data
  • rajatshrm648/purr-data
  • Srashti/purr-data
  • Paarth/purr-data
  • AniruddhaGawali/purr-data
  • brittneyjuliet/purr-data
  • prakharagarwal1/purr-data
  • Shreyanshpaliwalcmsmn/purr-data
  • k_amrut/purr-data
  • AyushAnand/purr-data
  • Va16hav07/purr-data
36 results
Show changes
Showing
with 1434 additions and 46 deletions
lib.name = bendinfix
class.sources = bendinfix.c
datafiles = bendinfix-help.pd LICENSE README.md
include Makefile.pdlibbuilder.revised
This diff is collapsed.
# bendinfix
This external provides a helper object to maintain compatibility between the bendin value ranges of different Pd flavors (specifically, vanilla Pd, pd-l2ork version 1, and purr-data a.k.a. pd-l2ork version 2+).
Pd has a long-standing [bug](https://sourceforge.net/p/pure-data/bugs/1262/) in that its bendin object produces an unsigned value range of 0 thru 16383, while the bendout object expects a signed range of -8192 thru +8191. Which means that you have to translate the values when routing pitch bends from MIDI input to MIDI output. It also makes it harder to translate pitch bend input to frequency offsets. This bug has been there for such a long time that it now can't be fixed any more, to maintain backwards compatibility.
However, other Pd flavors have in fact fixed this bug, specifically pd-l2ork and its successor purr-data. This actually made matters worse, though, since now Pd programmers have to cope with a variety of bendin implementations, which makes it hard to maintain interoperability between the different flavors if you need to process MIDI pitch bend events.
The bendinfix external provides a solution that (1) provides a quick way to check which bendin implementation you have, (2) takes the output of the bendin object and translates it to the correct (signed) range, and (3) is binary-compatible with all modern Pd flavors.
## Synopsis
`[bendin]` takes signed or unsigned pitch bend values and translates them to signed values.
- inlet #1: signed or unsigned pitch bend values, depending on your Pd flavor
- outlet #1: output values are always signed, in the -8192 ... 8191 range
- arguments: none
## Usage
(1) Passing 0 to bendinfix yields the value -8192 for a vanilla-compatible bendin, and 0 otherwise. Thus comparing the result against 0 gives you a flag determining whether you have a signed implementation:
`[0( --- [bendinfix] --- [== 0]` yields 1 if signed, 0 if unsigned bendin implementation
You can then use the computed flag in a patch to set it up for the pitch bend implementation at hand.
(2) Simply routing the output of bendin into bendinfix yields the correct signed pitch bend values:
`[bendin] --- [bendinfix]` yields signed bendin values in the -8192 ... 8191 range
These can then be routed to bendout without further translation, or you can divide, e.g., by 4096, add a MIDI note number, and route the result through mtof to get a pitch bend range of +/- 2 semitones.
Or, if you prefer to work with unsigned values, just add 8192 to the result of bendinfix. This will always give you unsigned values, even if your Pd flavor has a signed bendin implementation.
## See Also
- the infamous [bug #1262](https://sourceforge.net/p/pure-data/bugs/1262/)
- doc/5.reference, midi (and bendin) help patches
#N canvas 696 372 460 365 12;
#X obj 22 263 bendinfix;
#X floatatom 22 292 5 0 0 0 - - -, f 5;
#X msg 78 233 0;
#X obj 22 233 bendin;
#X text 21 321 corrected pitch bend value (-8192 - 8191 range);
#X text 22 206 pitch bend input;
#X text 113 234 Passing 0 as input gives the amount by which the result
is shifted. This will be -8192 for a vanilla-compatible bendin implementation
\, 0 otherwise., f 46;
#N canvas 477 282 494 344 META 0;
#X text 12 5 KEYWORDS control MIDI;
#X text 12 25 LICENSE MIT;
#X text 12 85 INLET_0 float;
#X text 12 105 OUTLET_0 float;
#X text 12 129 AUTHOR Albert Gräf;
#X text 12 149 WEBSITE https://agraef.github.io/purr-data/;
#X text 12 169 RELEASE_DATE 2020;
#X text 12 192 HELP_PATCH_AUTHORS Albert Gräf;
#X text 12 45 DESCRIPTION translate bendin output to signed values
for all Pd flavors;
#X restore 380 335 pd META;
#X text 18 2 bendinfix - correct bendin values for all Pd flavors;
#X text 17 41 Background: Pd has a long-standing bug (which won't be
fixed due to backward compatibility concerns) in that its bendin range
(0 - 16383) doesn't match its bendout range (-8192 - 8191). The former
is what MIDI readily yields \, while the latter is more convenient
for translating pitch bends into frequency offsets. The bendinfix object
translates bendin's output to the correct (signed) range \, and works
across all Pd flavors \, including Pd-L2ork and Purr Data where bendin
returns a signed result by default.;
#X connect 0 0 1 0;
#X connect 2 0 0 0;
#X connect 3 0 0 0;
// To compile on Linux: gcc --shared -fPIC -o bendinfix.pd_linux bendinfix.c
#include <m_pd.h>
static t_class *bendinfix_class;
static int *legacy, *legacy_bendin;
static void (*nw_gui_vmess)(const char *sel, char *fmt, ...);
typedef struct _bendinfix {
t_object x_obj;
} t_bendinfix;
void bendinfix_float(t_bendinfix *x, t_floatarg f)
{
// vanilla default:
t_float g = 8192;
// exported symbols by the different Pd flavors:
// nw_gui_vmess => purr-data only
// legacy => pd-l2ork and purr-data
// legacy_bendin => purr-data with revised bendin implementation
if (legacy_bendin)
// signed bendin unless legacy_bendin is set
g = *legacy_bendin?8192:0;
else if (legacy)
// we always have a signed bendin with classic pd-l2ork (!nw_gui_vmess),
// whereas for purr-data without the revised bendin implementation
// (!legacy_bendin) bendin is signed, unless legacy is set
g = !nw_gui_vmess?0:*legacy?8192:0;
outlet_float(x->x_obj.ob_outlet, f-g);
}
void *bendinfix_new(void)
{
t_bendinfix *x = (t_bendinfix *)pd_new(bendinfix_class);
outlet_new(&x->x_obj, &s_float);
return (void *)x;
}
#ifdef WIN32
#include <windows.h>
#else
#define __USE_GNU // to get RTLD_DEFAULT
#include <dlfcn.h> // for dlsym
#ifndef RTLD_DEFAULT
/* If RTLD_DEFAULT still isn't defined then just passing NULL will hopefully
do the trick. */
#define RTLD_DEFAULT NULL
#endif
#endif
void bendinfix_setup(void) {
bendinfix_class = class_new(gensym("bendinfix"),
(t_newmethod)bendinfix_new,
0, sizeof(t_bendinfix),
CLASS_DEFAULT, 0);
class_addfloat(bendinfix_class, bendinfix_float);
#ifdef WIN32
legacy = (void*)GetProcAddress(GetModuleHandle("pd.dll"), "sys_legacy");
legacy_bendin = (void*)GetProcAddress(GetModuleHandle("pd.dll"), "sys_legacy_bendin");
nw_gui_vmess = (void*)GetProcAddress(GetModuleHandle("pd.dll"), "gui_vmess");
#else
legacy = dlsym(RTLD_DEFAULT, "sys_legacy");
legacy_bendin = dlsym(RTLD_DEFAULT, "sys_legacy_bendin");
nw_gui_vmess = dlsym(RTLD_DEFAULT, "gui_vmess");
#endif
}
......@@ -42,6 +42,10 @@ LIBS =
#
#------------------------------------------------------------------------------#
ifeq ($(macos_target),)
macos_target = 10.9
endif
# get library version from meta file
LIBRARY_VERSION = $(shell sed -n 's|^\#X text [0-9][0-9]* [0-9][0-9]* VERSION \(.*\);|\1|p' $(LIBRARY_NAME)-meta.pd)
......@@ -68,7 +72,7 @@ ORIGDIR=pd-$(LIBRARY_NAME:~=)_$(LIBRARY_VERSION)
UNAME := $(shell uname -s)
ifeq ($(UNAME),Darwin)
CPU := $(shell uname -p)
ifeq ($(CPU),arm) # iPhone/iPod Touch
ifeq ($(CPU),arm-iphone) # iPhone/iPod Touch
SOURCES += $(SOURCES_iphoneos)
EXTENSION = pd_darwin
OS = iphoneos
......@@ -93,13 +97,13 @@ ifeq ($(UNAME),Darwin)
OPT_CFLAGS = -ftree-vectorize -ftree-vectorizer-verbose=2 -fast
# build universal 32-bit on 10.4 and 32/64 on newer
ifeq ($(shell uname -r | sed 's|\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*|\1|'), 8)
FAT_FLAGS = -arch ppc -arch i386 -mmacosx-version-min=10.4
FAT_FLAGS = -arch ppc -arch i386 -mmacosx-version-min=$(macos_target)
else
FAT_FLAGS = -arch ppc -arch i386 -arch x86_64 -mmacosx-version-min=10.4
FAT_FLAGS = -arch ppc -arch i386 -arch x86_64 -mmacosx-version-min=$(macos_target)
SOURCES += $(SOURCES_iphoneos)
endif
CFLAGS += $(FAT_FLAGS) -fPIC -I/sw/include
LDFLAGS += $(FAT_FLAGS) -bundle -undefined dynamic_lookup -L/sw/lib
CFLAGS += $(FAT_FLAGS) -fPIC
LDFLAGS += $(FAT_FLAGS) -bundle -undefined dynamic_lookup
# if the 'pd' binary exists, check the linking against it to aid with stripping
LDFLAGS += $(shell test -e $(PD_PATH)/bin/pd && echo -bundle_loader $(PD_PATH)/bin/pd)
LIBS += -lc
......
This diff is collapsed.
......@@ -99,7 +99,7 @@ static t_int *aenv_perform(t_int *w)
static void aenv_dsp(t_aenv *x, t_signal **sp)
{
dsp_add(aenv_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
dsp_add(aenv_perform, 3, x, sp[0]->s_vec, (t_int)sp[0]->s_n);
}
static void aenv_float(t_aenv *x, t_float f)
......
This diff is collapsed.
......@@ -258,7 +258,7 @@ static t_int *pvoc_perform(t_int *w)
static void pvoc_dsp(t_pvoc *x, t_signal **sp)
{
dsp_add(pvoc_perform, 5, x, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
dsp_add(pvoc_perform, 5, x, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, (t_int)sp[0]->s_n);
}
// adapted from jsarlo's windowing library
......
......@@ -88,7 +88,7 @@ static t_int *susloop_perform(t_int *w)
static void susloop_dsp(t_susloop *x, t_signal **sp)
{
dsp_add(susloop_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
dsp_add(susloop_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, (t_int)sp[0]->s_n);
}
static void *susloop_new(t_symbol *s, int argc, t_atom *argv)
......
......@@ -124,7 +124,7 @@ static t_int *svf_perform(t_int *w)
static void svf_dsp(t_svf *x, t_signal **sp)
{
dsp_add(svf_perform, 7, x, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec, sp[0]->s_n);
dsp_add(svf_perform, 7, x, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec, (t_int)sp[0]->s_n);
}
static void *svf_new(t_symbol *s, int argc, t_atom *argv)
......
......@@ -59,7 +59,7 @@ static t_int *zhzxh_perform(t_int *w)
static void zhzxh_dsp(t_zhzxh *x, t_signal **sp)
{
dsp_add(zhzxh_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
dsp_add(zhzxh_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, (t_int)sp[0]->s_n);
}
static void *zhzxh_new(t_symbol *s, int argc, t_atom *argv)
......
......@@ -33,8 +33,8 @@ OPTIM_FLAGS = -mpowerpc-gpopt -mcpu=750
CFLAGS = -DPD -DUNIX -DMACOSX -Dunix $(OPTIM_FLAGS) \
-Wall -W -Wno-unused -Wno-parentheses -Wno-switch -Wno-shadow
INCLUDES = -I$(pd_src)/src -I/sw/include
LDFLAGS = -bundle -bundle_loader $(PDEXECUTABLE) -L/sw/lib
INCLUDES = -I$(pd_src)/src
LDFLAGS = -bundle -bundle_loader $(PDEXECUTABLE)
externals: $(EXTERNALS:.c=.pd_darwin)
......
......@@ -77,7 +77,7 @@ static t_int *biquadseries_perform(t_int *w)
static void biquadseries_dsp(t_biquadseries *x, t_signal **sp)
{
dsp_add(biquadseries_perform, 4, x->biquadseries, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec);
dsp_add(biquadseries_perform, 4, x->biquadseries, (t_int)sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec);
}
void biquadseries_free(void)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.