From 878ee3f2844f1c2cdbf14e3f9b9acbd43bdd9edf Mon Sep 17 00:00:00 2001 From: Ed Kelly Date: Sat, 15 Sep 2012 13:29:19 +0000 Subject: gemnotes 0.2.3 svn path=/trunk/externals/ekext/; revision=16237 --- gemnotes_0.2.3/src/LICENSE.txt | 29 + gemnotes_0.2.3/src/Makefile | 406 +++++++++ gemnotes_0.2.3/src/ekext-meta.pd | 6 + gemnotes_0.2.3/src/gemnotes_countbars.c | 255 ++++++ gemnotes_0.2.3/src/gemnotes_counter-help.pd | 68 ++ gemnotes_0.2.3/src/gemnotes_counter.c | 1267 +++++++++++++++++++++++++++ gemnotes_0.2.3/src/polyquant-help.pd | 61 ++ gemnotes_0.2.3/src/polyquant.c | 178 ++++ 8 files changed, 2270 insertions(+) create mode 100755 gemnotes_0.2.3/src/LICENSE.txt create mode 100755 gemnotes_0.2.3/src/Makefile create mode 100755 gemnotes_0.2.3/src/ekext-meta.pd create mode 100755 gemnotes_0.2.3/src/gemnotes_countbars.c create mode 100755 gemnotes_0.2.3/src/gemnotes_counter-help.pd create mode 100755 gemnotes_0.2.3/src/gemnotes_counter.c create mode 100755 gemnotes_0.2.3/src/polyquant-help.pd create mode 100755 gemnotes_0.2.3/src/polyquant.c (limited to 'gemnotes_0.2.3/src') diff --git a/gemnotes_0.2.3/src/LICENSE.txt b/gemnotes_0.2.3/src/LICENSE.txt new file mode 100755 index 0000000..edfda65 --- /dev/null +++ b/gemnotes_0.2.3/src/LICENSE.txt @@ -0,0 +1,29 @@ +This software is copyrighted by Edward Kelly. The following +terms (the "Standard Improved BSD License") apply to all files associated with the software unless explicitly disclaimed in individual files: + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. +3. The name of the author may not be used to endorse or promote + products derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGE. diff --git a/gemnotes_0.2.3/src/Makefile b/gemnotes_0.2.3/src/Makefile new file mode 100755 index 0000000..21578d3 --- /dev/null +++ b/gemnotes_0.2.3/src/Makefile @@ -0,0 +1,406 @@ +## Pd library template version 1.0.11 +# For instructions on how to use this template, see: +# http://puredata.info/docs/developer/MakefileTemplate +LIBRARY_NAME = ekext + +# add your .c source files, one object per file, to the SOURCES +# variable, help files will be included automatically +SOURCES = gemnotes_countbars.c polyquant.c gemnotes_counter.c + +# list all pd objects (i.e. myobject.pd) files here, and their helpfiles will +# be included automatically +PDOBJECTS = + +# example patches and related files, in the 'examples' subfolder +EXAMPLES = + +# manuals and related files, in the 'manual' subfolder +MANUAL = + +# if you want to include any other files in the source and binary tarballs, +# list them here. This can be anything from header files, test patches, +# documentation, etc. README.txt and LICENSE.txt are required and therefore +# automatically included +EXTRA_DIST = peakit~_license.txt voicing_detector~test3-help.pd maskxor-test.pd + + + +#------------------------------------------------------------------------------# +# +# things you might need to edit if you are using other C libraries +# +#------------------------------------------------------------------------------# + +ALL_CFLAGS = -I"$(PD_INCLUDE)" +ALL_LDFLAGS = +SHARED_LDFLAGS = +ALL_LIBS = + + +#------------------------------------------------------------------------------# +# +# you shouldn't need to edit anything below here, if we did it right :) +# +#------------------------------------------------------------------------------# + +# these can be set from outside without (usually) breaking the build +CFLAGS = -Wall -W -g +LDFLAGS = +LIBS = + +# 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) + +ALL_CFLAGS += -DPD -DVERSION='"$(LIBRARY_VERSION)"' + +PD_INCLUDE = $(PD_PATH)/include/pd +# where to install the library, overridden below depending on platform +prefix = /usr/local +libdir = $(prefix)/lib +pkglibdir = $(libdir)/pd-externals +objectsdir = $(pkglibdir) + +INSTALL = install +INSTALL_PROGRAM = $(INSTALL) -p -m 644 +INSTALL_DATA = $(INSTALL) -p -m 644 +INSTALL_DIR = $(INSTALL) -p -m 755 -d + +ALLSOURCES := $(SOURCES) $(SOURCES_android) $(SOURCES_cygwin) $(SOURCES_macosx) \ + $(SOURCES_iphoneos) $(SOURCES_linux) $(SOURCES_windows) + +DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) +ORIGDIR=pd-$(LIBRARY_NAME:~=)_$(LIBRARY_VERSION) + +UNAME := $(shell uname -s) +ifeq ($(UNAME),Darwin) + CPU := $(shell uname -p) + ifeq ($(CPU),arm) # iPhone/iPod Touch + SOURCES += $(SOURCES_iphoneos) + EXTENSION = pd_darwin + SHARED_EXTENSION = dylib + OS = iphoneos + PD_PATH = /Applications/Pd-extended.app/Contents/Resources + IPHONE_BASE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin + CC=$(IPHONE_BASE)/gcc + CPP=$(IPHONE_BASE)/cpp + CXX=$(IPHONE_BASE)/g++ + ISYSROOT = -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk + IPHONE_CFLAGS = -miphoneos-version-min=3.0 $(ISYSROOT) -arch armv6 + OPT_CFLAGS = -fast -funroll-loops -fomit-frame-pointer + ALL_CFLAGS := $(IPHONE_CFLAGS) $(ALL_CFLAGS) + ALL_LDFLAGS += -arch armv6 -bundle -undefined dynamic_lookup $(ISYSROOT) + SHARED_LDFLAGS += -arch armv6 -dynamiclib -undefined dynamic_lookup $(ISYSROOT) + ALL_LIBS += -lc $(LIBS_iphoneos) + STRIP = strip -x + DISTBINDIR=$(DISTDIR)-$(OS) + else # Mac OS X + SOURCES += $(SOURCES_macosx) + EXTENSION = pd_darwin + SHARED_EXTENSION = dylib + OS = macosx + PD_PATH = /Applications/Pd-extended.app/Contents/Resources + OPT_CFLAGS = -ftree-vectorize -ftree-vectorizer-verbose=2 -fast +# build universal 32-bit on 10.4 and 32/64 on newer + FAT_FLAGS = -arch i386 -mmacosx-version-min=10.4 +# FAT_FLAGS = -arch i386 -arch x86_64 -mmacosx-version-min=10.4 + SOURCES += $(SOURCES_iphoneos) + ALL_CFLAGS += $(FAT_FLAGS) -fPIC -I/sw/include + # if the 'pd' binary exists, check the linking against it to aid with stripping + BUNDLE_LOADER = $(shell test ! -e $(PD_PATH)/bin/pd || echo -bundle_loader $(PD_PATH)/bin/pd) + ALL_LDFLAGS += $(FAT_FLAGS) -bundle $(BUNDLE_LOADER) -undefined dynamic_lookup -L/sw/lib + SHARED_LDFLAGS += $(FAT_FLAGS) -dynamiclib -undefined dynamic_lookup \ + -install_name @loader_path/$(SHARED_LIB) -compatibility_version 1 -current_version 1.0 + ALL_LIBS += -lc $(LIBS_macosx) + STRIP = strip -x + DISTBINDIR=$(DISTDIR)-$(OS) +# install into ~/Library/Pd on Mac OS X since /usr/local isn't used much + pkglibdir=$(HOME)/Library/Pd + endif +endif +# Tho Android uses Linux, we use this fake uname to provide an easy way to +# setup all this things needed to cross-compile for Android using the NDK +ifeq ($(UNAME),ANDROID) + CPU := arm + SOURCES += $(SOURCES_android) + EXTENSION = pd_linux + SHARED_EXTENSION = so + OS = android + PD_PATH = /usr + NDK_BASE := /usr/local/android-ndk + NDK_PLATFORM_VERSION := 5 + NDK_SYSROOT=$(NDK_BASE)/platforms/android-$(NDK_PLATFORM_VERSION)/arch-arm + NDK_UNAME := $(shell uname -s | tr '[A-Z]' '[a-z]') + NDK_TOOLCHAIN_BASE=$(NDK_BASE)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$(NDK_UNAME)-x86 + CC := $(NDK_TOOLCHAIN_BASE)/bin/arm-linux-androideabi-gcc --sysroot=$(NDK_SYSROOT) + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + CFLAGS += + LDFLAGS += -rdynamic -shared + SHARED_LDFLAGS += -Wl,-soname,$(SHARED_LIB) -shared + LIBS += -lc $(LIBS_android) + STRIP := $(NDK_TOOLCHAIN_BASE)/bin/arm-linux-androideabi-strip \ + --strip-unneeded -R .note -R .comment + DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) +endif +ifeq ($(UNAME),Linux) + CPU := $(shell uname -m) + SOURCES += $(SOURCES_linux) + EXTENSION = pd_linux + SHARED_EXTENSION = so + OS = linux + PD_PATH = /usr + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + ALL_CFLAGS += -fPIC + ALL_LDFLAGS += -rdynamic -shared -fPIC + SHARED_LDFLAGS += -Wl,-soname,$(SHARED_LIB) -shared + ALL_LIBS += -lc $(LIBS_linux) + STRIP = strip --strip-unneeded -R .note -R .comment + DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) +endif +ifeq ($(UNAME),GNU) + # GNU/Hurd, should work like GNU/Linux for basically all externals + CPU := $(shell uname -m) + SOURCES += $(SOURCES_linux) + EXTENSION = pd_linux + SHARED_EXTENSION = so + OS = linux + PD_PATH = /usr + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + ALL_CFLAGS += -fPIC + ALL_LDFLAGS += -rdynamic -shared -fPIC + SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB) + ALL_LIBS += -lc $(LIBS_linux) + STRIP = strip --strip-unneeded -R .note -R .comment + DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) +endif +ifeq ($(UNAME),GNU/kFreeBSD) + # Debian GNU/kFreeBSD, should work like GNU/Linux for basically all externals + CPU := $(shell uname -m) + SOURCES += $(SOURCES_linux) + EXTENSION = pd_linux + SHARED_EXTENSION = so + OS = linux + PD_PATH = /usr + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + ALL_CFLAGS += -fPIC + ALL_LDFLAGS += -rdynamic -shared -fPIC + SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB) + ALL_LIBS += -lc $(LIBS_linux) + STRIP = strip --strip-unneeded -R .note -R .comment + DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) +endif +ifeq (CYGWIN,$(findstring CYGWIN,$(UNAME))) + CPU := $(shell uname -m) + SOURCES += $(SOURCES_cygwin) + EXTENSION = dll + SHARED_EXTENSION = dll + OS = cygwin + PD_PATH = $(shell cygpath $$PROGRAMFILES)/pd + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + ALL_CFLAGS += + ALL_LDFLAGS += -rdynamic -shared -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" + SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB) + ALL_LIBS += -lc -lpd $(LIBS_cygwin) + STRIP = strip --strip-unneeded -R .note -R .comment + DISTBINDIR=$(DISTDIR)-$(OS) +endif +ifeq (MINGW,$(findstring MINGW,$(UNAME))) + CPU := $(shell uname -m) + SOURCES += $(SOURCES_windows) + EXTENSION = dll + SHARED_EXTENSION = dll + OS = windows + PD_PATH = $(shell cd "$$PROGRAMFILES/pd" && pwd) + # MinGW doesn't seem to include cc so force gcc + CC=gcc + OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer + ALL_CFLAGS += -mms-bitfields + ALL_LDFLAGS += -s -shared -Wl,--enable-auto-import -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" -L"$(PD_PATH)/obj" + SHARED_LDFLAGS += -shared + ALL_LIBS += -lpd -lwsock32 -lkernel32 -luser32 -lgdi32 $(LIBS_windows) + STRIP = strip --strip-unneeded -R .note -R .comment + DISTBINDIR=$(DISTDIR)-$(OS) +endif + +# in case somebody manually set the HELPPATCHES above +HELPPATCHES ?= $(SOURCES:.c=-help.pd) $(PDOBJECTS:.pd=-help.pd) + +ALL_CFLAGS := $(ALL_CFLAGS) $(CFLAGS) $(OPT_CFLAGS) +ALL_LDFLAGS := $(LDFLAGS) $(ALL_LDFLAGS) +ALL_LIBS := $(LIBS) $(ALL_LIBS) + +SHARED_SOURCE ?= $(shell test ! -e lib$(LIBRARY_NAME).c || \ + echo lib$(LIBRARY_NAME).c ) +SHARED_HEADER ?= $(shell test ! -e $(LIBRARY_NAME).h || echo $(LIBRARY_NAME).h) +SHARED_LIB = $(SHARED_SOURCE:.c=.$(SHARED_EXTENSION)) + +.PHONY = install libdir_install single_install install-doc install-examples install-manual clean distclean dist etags $(LIBRARY_NAME) + +all: $(SOURCES:.c=.$(EXTENSION)) $(SHARED_LIB) + +%.o: %.c + $(CC) $(ALL_CFLAGS) -o "$*.o" -c "$*.c" + +%.$(EXTENSION): %.o $(SHARED_LIB) + $(CC) $(ALL_LDFLAGS) -o "$*.$(EXTENSION)" "$*.o" $(ALL_LIBS) $(SHARED_LIB) + chmod a-x "$*.$(EXTENSION)" + +# this links everything into a single binary file +$(LIBRARY_NAME): $(SOURCES:.c=.o) $(LIBRARY_NAME).o + $(CC) $(ALL_LDFLAGS) -o $(LIBRARY_NAME).$(EXTENSION) $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(ALL_LIBS) + chmod a-x $(LIBRARY_NAME).$(EXTENSION) + +$(SHARED_LIB): $(SHARED_SOURCE:.c=.o) + $(CC) $(SHARED_LDFLAGS) -o $(SHARED_LIB) $(SHARED_SOURCE:.c=.o) $(LIBS) + +install: libdir_install + +# The meta and help files are explicitly installed to make sure they are +# actually there. Those files are not optional, then need to be there. +libdir_install: $(SOURCES:.c=.$(EXTENSION)) $(SHARED_LIB) install-doc install-examples install-manual + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + test -z "$(strip $(SOURCES))" || (\ + $(INSTALL_PROGRAM) $(SOURCES:.c=.$(EXTENSION)) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) && \ + $(STRIP) $(addprefix $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/,$(SOURCES:.c=.$(EXTENSION)))) + test -z "$(strip $(SHARED_LIB))" || \ + $(INSTALL_DATA) $(SHARED_LIB) \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + test -z "$(strip $(wildcard $(SOURCES:.c=.tcl)))" || \ + $(INSTALL_DATA) $(wildcard $(SOURCES:.c=.tcl)) \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + test -z "$(strip $(PDOBJECTS))" || \ + $(INSTALL_DATA) $(PDOBJECTS) \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + +# install library linked as single binary +single_install: $(LIBRARY_NAME) install-doc install-examples install-manual + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + $(INSTALL_PROGRAM) $(LIBRARY_NAME).$(EXTENSION) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + $(STRIP) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/$(LIBRARY_NAME).$(EXTENSION) + +install-doc: + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + test -z "$(strip $(SOURCES) $(PDOBJECTS))" || \ + $(INSTALL_DATA) $(HELPPATCHES) \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + $(INSTALL_DATA) README.txt $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/README.txt + $(INSTALL_DATA) LICENSE.txt $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/LICENSE.txt + +install-examples: + test -z "$(strip $(EXAMPLES))" || \ + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples && \ + for file in $(EXAMPLES); do \ + $(INSTALL_DATA) examples/$$file $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples; \ + done + +install-manual: + test -z "$(strip $(MANUAL))" || \ + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/manual && \ + for file in $(MANUAL); do \ + $(INSTALL_DATA) manual/$$file $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/manual; \ + done + + +clean: + -rm -f -- $(SOURCES:.c=.o) $(SOURCES_LIB:.c=.o) $(SHARED_SOURCE:.c=.o) + -rm -f -- $(SOURCES:.c=.$(EXTENSION)) + -rm -f -- $(LIBRARY_NAME).o + -rm -f -- $(LIBRARY_NAME).$(EXTENSION) + -rm -f -- $(SHARED_LIB) + +distclean: clean + -rm -f -- $(DISTBINDIR).tar.gz + -rm -rf -- $(DISTBINDIR) + -rm -f -- $(DISTDIR).tar.gz + -rm -rf -- $(DISTDIR) + -rm -f -- $(ORIGDIR).tar.gz + -rm -rf -- $(ORIGDIR) + + +$(DISTBINDIR): + $(INSTALL_DIR) $(DISTBINDIR) + +libdir: all $(DISTBINDIR) + $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd $(DISTBINDIR) + $(INSTALL_DATA) $(SOURCES) $(SHARED_SOURCE) $(SHARED_HEADER) $(DISTBINDIR) + $(INSTALL_DATA) $(HELPPATCHES) $(DISTBINDIR) + test -z "$(strip $(EXTRA_DIST))" || \ + $(INSTALL_DATA) $(EXTRA_DIST) $(DISTBINDIR) +# tar --exclude-vcs -czpf $(DISTBINDIR).tar.gz $(DISTBINDIR) + +$(DISTDIR): + $(INSTALL_DIR) $(DISTDIR) + +$(ORIGDIR): + $(INSTALL_DIR) $(ORIGDIR) + +dist: $(DISTDIR) + $(INSTALL_DATA) Makefile $(DISTDIR) + $(INSTALL_DATA) README.txt $(DISTDIR) + $(INSTALL_DATA) LICENSE.txt $(DISTDIR) + $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd $(DISTDIR) + test -z "$(strip $(ALLSOURCES))" || \ + $(INSTALL_DATA) $(ALLSOURCES) $(DISTDIR) + test -z "$(strip $(wildcard $(ALLSOURCES:.c=.tcl)))" || \ + $(INSTALL_DATA) $(wildcard $(ALLSOURCES:.c=.tcl)) $(DISTDIR) + test -z "$(strip $(SHARED_HEADER))" || \ + $(INSTALL_DATA) $(SHARED_HEADER) $(DISTDIR) + test -z "$(strip $(SHARED_SOURCE))" || \ + $(INSTALL_DATA) $(SHARED_SOURCE) $(DISTDIR) + test -z "$(strip $(PDOBJECTS))" || \ + $(INSTALL_DATA) $(PDOBJECTS) $(DISTDIR) + test -z "$(strip $(HELPPATCHES))" || \ + $(INSTALL_DATA) $(HELPPATCHES) $(DISTDIR) + test -z "$(strip $(EXTRA_DIST))" || \ + $(INSTALL_DATA) $(EXTRA_DIST) $(DISTDIR) + test -z "$(strip $(EXAMPLES))" || \ + $(INSTALL_DIR) $(DISTDIR)/examples && \ + for file in $(EXAMPLES); do \ + $(INSTALL_DATA) examples/$$file $(DISTDIR)/examples; \ + done + test -z "$(strip $(MANUAL))" || \ + $(INSTALL_DIR) $(DISTDIR)/manual && \ + for file in $(MANUAL); do \ + $(INSTALL_DATA) manual/$$file $(DISTDIR)/manual; \ + done + tar --exclude-vcs -czpf $(DISTDIR).tar.gz $(DISTDIR) + +# make a Debian source package +dpkg-source: + debclean + make distclean dist + mv $(DISTDIR) $(ORIGDIR) + tar --exclude-vcs -czpf ../$(ORIGDIR).orig.tar.gz $(ORIGDIR) + rm -f -- $(DISTDIR).tar.gz + rm -rf -- $(DISTDIR) $(ORIGDIR) + cd .. && dpkg-source -b $(LIBRARY_NAME) + +etags: + etags *.h $(SOURCES) ../../pd/src/*.[ch] /usr/include/*.h /usr/include/*/*.h + +showsetup: + @echo "CC: $(CC)" + @echo "CFLAGS: $(CFLAGS)" + @echo "LDFLAGS: $(LDFLAGS)" + @echo "LIBS: $(LIBS)" + @echo "ALL_CFLAGS: $(ALL_CFLAGS)" + @echo "ALL_LDFLAGS: $(ALL_LDFLAGS)" + @echo "ALL_LIBS: $(ALL_LIBS)" + @echo "PD_INCLUDE: $(PD_INCLUDE)" + @echo "PD_PATH: $(PD_PATH)" + @echo "objectsdir: $(objectsdir)" + @echo "LIBRARY_NAME: $(LIBRARY_NAME)" + @echo "LIBRARY_VERSION: $(LIBRARY_VERSION)" + @echo "SOURCES: $(SOURCES)" + @echo "SHARED_HEADER: $(SHARED_HEADER)" + @echo "SHARED_SOURCE: $(SHARED_SOURCE)" + @echo "SHARED_LIB: $(SHARED_LIB)" + @echo "PDOBJECTS: $(PDOBJECTS)" + @echo "ALLSOURCES: $(ALLSOURCES)" + @echo "ALLSOURCES TCL: $(wildcard $(ALLSOURCES:.c=.tcl))" + @echo "UNAME: $(UNAME)" + @echo "CPU: $(CPU)" + @echo "pkglibdir: $(pkglibdir)" + @echo "DISTDIR: $(DISTDIR)" + @echo "ORIGDIR: $(ORIGDIR)" diff --git a/gemnotes_0.2.3/src/ekext-meta.pd b/gemnotes_0.2.3/src/ekext-meta.pd new file mode 100755 index 0000000..3d50706 --- /dev/null +++ b/gemnotes_0.2.3/src/ekext-meta.pd @@ -0,0 +1,6 @@ +#N canvas 15 49 200 200 10; +#N canvas 25 49 420 300 META 0; +#X text 13 41 NAME ekext; +#X text 10 25 AUTHOR Ed Kelly; +#X text 10 10 VERSION 0.1.3; +#X restore 10 10 pd META; diff --git a/gemnotes_0.2.3/src/gemnotes_countbars.c b/gemnotes_0.2.3/src/gemnotes_countbars.c new file mode 100755 index 0000000..4650d22 --- /dev/null +++ b/gemnotes_0.2.3/src/gemnotes_countbars.c @@ -0,0 +1,255 @@ +#include "m_pd.h" +#include + +static t_class *gemnotes_countbars_class; + +/* list inlet: [rhythm dur vel start] + * when the BPM changes, the offset accumulates the start time of the first + * note, and is subtracted from subsequent inter-onset times + */ + +/* The Gemnotes system can only handle one voice at the moment. */ + +/* this object is probably where key signatures (flatsharp flag) and dynamics + * will be calculated eventually, since it has access to the pitch and + * velocity information + */ + +typedef struct _gemnotes_countbars { + t_object x_obj; + t_atom outlist[5]; + t_float bpm, qtime, divtime, numer, denom; + // int setoffset, iotdiv; + t_float allcount, barcount, barlen, bardiv, iot, offset, rhythm, dur, notedur, nbars; + t_float start, pitch, vel; + t_float prevstart, previot, prevdurt, prevdur, tdiff, polydiff; + t_float outstart; + int ndurs, polycompare, debug; + t_outlet *note, *bars; +} t_gemnotes_countbars; + +/* There are real problems with this algorithm. Firstly it assumes that all notes + * are not polyrhythmic against the basic pulse, so manual editing of the score + * will be necessary if there are polyrhythmic note divisions. Secondly, there can + * only be one voice with chords. + * Perhaps this should all be folded into polyquant, with polyquant + * measuring all 136 MIDI timings internally... + * ...for live input transcription, there would need to be quantization + * of the inter-onset time. + * I need to learn about clocks in PD! + */ + +void gemnotes_countbars_note (t_gemnotes_countbars *z, t_symbol *s, int argc, t_atom *argv) +{ + float newcount = 0; + if(argc == 5) + { + z->prevstart = z->start; + z->prevdur = z->dur; + + z->pitch = atom_getfloat(argv); + z->rhythm = atom_getfloat(argv+1); + z->dur = atom_getfloat(argv+2); + z->vel = atom_getfloat(argv+3); + z->start = atom_getfloat(argv+4); + + z->prevdurt = z->notedur; + z->notedur = z->divtime * z->dur; + + + z->previot = z->iot; + z->iot = z->start - z->prevstart; + + z->tdiff = z->iot - z->prevdurt; + z->outstart = 0; + /* Deal with polyrhythmic notes - a kludge until polyquant is integrated with this object */ + z->polydiff = z->iot / z->divtime; + z->polycompare = (int)z->polydiff; + if(z->tdiff < 2 && z->tdiff > -2 && z->allcount > 0) + { + newcount = z->barcount + z->prevdur; + if(newcount >= z->barlen) + { + z->nbars++; + outlet_float(z->bars, z->nbars); + } + z->barcount = (float)((int)newcount % (int)z->barlen); + z->allcount++; + if(z->debug == 1) post("barcount = %d, barlen = %d, + sign",(int)z->barcount, (int)z->barlen); + z->outstart = -1; + } + else if((float)z->polycompare - z->polydiff < -2) + { + newcount = z->barcount + z->polydiff; + if(newcount >= z->barlen) + { + z->nbars++; + outlet_float(z->bars, z->nbars); + newcount -= z->barlen; + z->barcount = newcount; + } + else if(newcount < z->barlen) + { + z->barcount = newcount; + } + z->outstart = z->barcount; + if(z->debug == 1) post("barcount = %d, barlen = %d, poly",(int)z->barcount, (int)z->barlen); + } + else if(z->iot < 2 && z->allcount > 0) + { + z->outstart = -2; + post("chord"); + } + else if(z->allcount == 0) + { + z->outstart = 0; + z->allcount++; + z->nbars = 1; + outlet_float(z->bars, z->nbars); + post("start"); + } + else if(z->tdiff > 1) + { + //assumes that the inter-onset time is always either 1 duration or more + //this bit will need to be changed for multi-voice scenarios to be supported + //but since it is proportional notation, maybe we can minimize rests + z->ndurs = 1; + while(z->tdiff > 1) + { + z->ndurs++; + z->tdiff -= z->divtime; + } + z->allcount += (float)z->ndurs; + newcount = (float)z->ndurs; + while(newcount >= z->barlen) + { + newcount -= z->barlen; + z->nbars++; + outlet_float(z->bars, z->nbars); + } + newcount += z->barcount; + if(newcount >= z->barlen) + { + z->nbars++; + outlet_float(z->bars, z->nbars); + } + z->barcount = (float)((int)(z->barcount + (float)z->ndurs) % (int)z->barlen); + z->outstart = z->barcount; + if(z->debug == 1) post("barcount = %d, barlen = %d - floatstart",(int)z->barcount, (int)z->barlen); + } + else + { + post("iot:%f,tdiff:%f,prevdur:%f,previot:%f,nomethod",z->iot, z->tdiff, z->prevdurt, z->previot); + } + SETFLOAT(&z->outlist[0], z->outstart); + SETFLOAT(&z->outlist[1], z->pitch); + SETFLOAT(&z->outlist[2], z->dur); + SETFLOAT(&z->outlist[4], z->vel); + outlet_list(z->note, gensym("list"), 5, z->outlist); + } +} + +void gemnotes_countbars_bpm (t_gemnotes_countbars *z, t_floatarg f) +{ + if(f != z->bpm && f > 0) + { + post("Tempo = %f Beats Per-Minute",f); + z->bpm = f; + // z->setoffset = 1; + z->qtime = 60000/f; + z->divtime = z->qtime / (z->bardiv / 4); + z->notedur = z->divtime * z->dur; + } +} + +void gemnotes_countbars_bar (t_gemnotes_countbars *z, t_symbol *s, int argc, t_atom *argv) +{ + if(argc > 2) + { + z->numer = atom_getfloat(argv); + z->denom = atom_getfloat(argv+1); + z->bardiv = atom_getfloat(argv+2); + z->barlen = z->numer / z->denom * z->bardiv; + z->divtime = z->qtime / (z->bardiv / 4); + z->prevdurt = z->divtime; + z->barcount = 0; + post("Bar of %d/%d, divisions: %d", (int)z->numer, (int)z->denom, (int)z->bardiv); + } + else if(argc > 1) + { + z->numer = atom_getfloat(argv); + z->denom = atom_getfloat(argv+1); + z->barlen = z->numer / z->denom * z->bardiv; + z->divtime = z->qtime / (z->bardiv / 4); + z->prevdurt = z->divtime; + z->barcount = 0; + post("Bar of %d/%d, divisions: %d", (int)z->numer, (int)z->denom, (int)z->bardiv); + } + else if(argc > 0) + { + z->numer = atom_getfloat(argv); + z->barlen = z->numer / z->denom * z->bardiv; + z->divtime = z->qtime / (z->bardiv / 4); + z->prevdurt = z->divtime; + z->barcount = 0; + post("Bar of %d/%d, divisions: %d", (int)z->numer, (int)z->denom, (int)z->bardiv); + } +} + +void gemnotes_countbars_debug(t_gemnotes_countbars *z, t_floatarg f) +{ + z->debug = f != 0 ? (int)f : 0; +} + +void gemnotes_countbars_reset(t_gemnotes_countbars *z) +{ + z->allcount = z->barcount = 0; + z->nbars = 1; +} + +void *gemnotes_countbars_new(t_symbol *s, int argc, t_atom *argv) +{ + t_gemnotes_countbars *z = (t_gemnotes_countbars *)pd_new(gemnotes_countbars_class); + int i; + for(i=0;i<5;i++) SETFLOAT(&z->outlist[i], 0); + + z->bpm = 120; + z->numer = 4; + z->denom = 4; + z->bardiv = 16; + // args: bpm, numer, denom, div + if(argc > 0) z->bpm = atom_getfloat(argv); + if(argc > 1) z->numer = atom_getfloat(argv+1); + if(argc > 2) z->denom = atom_getfloat(argv+2); + if(argc > 3) z->bardiv = atom_getfloat(argv+3); + + z->qtime = 60000/z->bpm; + z->divtime = z->qtime / (z->bardiv / z->denom); + z->prevdurt = z->divtime; + + z->barlen = z->numer / z->denom * z->bardiv; + z->barcount = z->allcount = 0; + z->previot = 0; + z->prevstart = -125; + z->nbars = 1; + z->note = outlet_new(&z->x_obj, gensym("list")); + z->bars = outlet_new(&z->x_obj, gensym("float")); + + return(void *)z; +} + +void gemnotes_countbars_setup(void) +{ + gemnotes_countbars_class = class_new(gensym("gemnotes_countbars"), + (t_newmethod)gemnotes_countbars_new, + 0, sizeof(t_gemnotes_countbars), + 0, A_GIMME, 0); + post("gemnotes_countbars - yu need this for realtime notation..."); + post("version 0.4...by Ed Kelly 2010 - morph_2016@yahoo.co.uk"); + + class_addmethod(gemnotes_countbars_class, (t_method)gemnotes_countbars_note, gensym("note"), A_GIMME, 0); + class_addmethod(gemnotes_countbars_class, (t_method)gemnotes_countbars_bar, gensym("bar"), A_GIMME, 0); + class_addmethod(gemnotes_countbars_class, (t_method)gemnotes_countbars_bpm, gensym("bpm"), A_DEFFLOAT, 0); + class_addmethod(gemnotes_countbars_class, (t_method)gemnotes_countbars_reset, gensym("reset"), A_DEFFLOAT, 0); + class_addmethod(gemnotes_countbars_class, (t_method)gemnotes_countbars_debug, gensym("debug"), A_DEFFLOAT, 0); +} diff --git a/gemnotes_0.2.3/src/gemnotes_counter-help.pd b/gemnotes_0.2.3/src/gemnotes_counter-help.pd new file mode 100755 index 0000000..e4ae13a --- /dev/null +++ b/gemnotes_0.2.3/src/gemnotes_counter-help.pd @@ -0,0 +1,68 @@ +#N canvas 0 0 590 490 10; +#X obj 190 141 gemnotes_counter; +#X floatatom 23 209 5 0 0 3 offset - -; +#X floatatom 62 209 5 0 0 3 rhythm - -; +#X floatatom 102 210 5 0 0 3 duration - -; +#X floatatom 158 210 5 0 0 3 grouplen - -; +#X floatatom 212 210 5 0 0 3 groupcount - -; +#X floatatom 290 207 5 0 0 3 rest_offset - -; +#X floatatom 361 208 5 0 0 3 rest_rhythm - -; +#X obj 259 173 tgl 15 0 empty empty beam -2 21 0 10 -262144 -1 -1 0 +1; +#X obj 236 173 tgl 15 0 empty empty tie -2 21 0 10 -262144 -1 -1 0 +1; +#X obj 401 190 bng 15 250 50 0 empty empty newbar -3 21 0 10 -262144 +-1 -1; +#X obj 116 36 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X obj 176 39 f; +#X floatatom 191 24 5 0 0 0 - - -; +#X obj 176 22 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X msg 245 37 bar 4 4 4 16; +#X msg 258 57 bar 6 8 6 16 4 16 2 16; +#X msg 249 91 step 1; +#X msg 314 93 step 2; +#X msg 362 94 allstep 0.11; +#X msg 363 115 allstep 0.18; +#X obj 97 281 cnv 15 300 150 empty empty gemnotes_milestones 20 12 +0 14 -204800 -13330 0; +#X text 123 309 Phase 1: build prototype objects.; +#X text 123 327 Phase 2: build prototype objectmakers; +#X text 124 345 Phase 3: build gemnotes_counter; +#X text 124 364 Phase 4: Implement and debug counter object; +#X text 125 382 Phase 5: build and link to score translator; +#X text 125 399 Phase 6: rehearse and perform Islands 1; +#X obj 103 309 tgl 15 1 empty empty empty 17 7 0 10 -262144 -1 -1 1 +1; +#X obj 103 327 tgl 15 1 empty empty empty 17 7 0 10 -262144 -1 -1 1 +1; +#X obj 103 345 tgl 15 1 empty empty empty 17 7 0 10 -262144 -1 -1 1 +1; +#X obj 103 363 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 +1; +#X obj 103 381 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 +1; +#X obj 103 399 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 +1; +#X text 406 345 September - December 2010; +#X connect 0 0 1 0; +#X connect 0 1 2 0; +#X connect 0 2 3 0; +#X connect 0 3 4 0; +#X connect 0 4 5 0; +#X connect 0 5 9 0; +#X connect 0 6 8 0; +#X connect 0 7 6 0; +#X connect 0 8 7 0; +#X connect 0 9 10 0; +#X connect 11 0 0 0; +#X connect 12 0 0 0; +#X connect 13 0 12 1; +#X connect 14 0 12 0; +#X connect 15 0 0 0; +#X connect 16 0 0 0; +#X connect 17 0 0 0; +#X connect 18 0 0 0; +#X connect 19 0 0 0; +#X connect 20 0 0 0; diff --git a/gemnotes_0.2.3/src/gemnotes_counter.c b/gemnotes_0.2.3/src/gemnotes_counter.c new file mode 100755 index 0000000..595e605 --- /dev/null +++ b/gemnotes_0.2.3/src/gemnotes_counter.c @@ -0,0 +1,1267 @@ +/* Gemnotes_counter is a beat, beamgroup and bar counter for the gemnotes system. + * It is used to count the elements of music notation, and to send commands to + * dynamic object makers to render notes, rests, time signatures and barlines. + * It keeps track of the number of obects created, and whether objects are linked + * together (such as beamed groups of notes). + * BSD license + */ + +#include "m_pd.h" +#include + +static int gemnotes_counter_splits[6][33] = { + /* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 */ + {0,1,2,3,4,3,6,4,8,6,6, 8, 8, 8, 8, 8, 8, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}, + {0,0,0,0,0,2,0,3,0,3,4, 3, 4, 3, 6, 4, 8, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}, + {0,0,0,0,0,0,0,0,0,0,0, 0, 0, 2, 0, 3, 0, 3, 6, 3, 4, 3, 6, 4, 8, 6, 8, 8, 8, 8, 8, 8, 8}, + {0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 3, 2, 3, 4, 3, 6, 4, 8}, + {0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0}, + {0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, +}; + +t_class *gemnotes_counter_class; + +typedef struct gemnotes_counter +{ + t_object x_obj; + t_atom groups[128]; + t_atom keysig[7]; + t_atom temposign[3]; + t_atom dynamics[5]; + t_atom terrace[2]; + t_float articulation; +// t_float artnote; + int numgroups, nowgroup, beforerest;//, lastgroup; + t_float allcount, allstep; + t_float barcount, barlen, barrem, numerator, denominator, nextnumer, nextdenom; + t_float groupcount, grouplen, groupnum, groupdiv, grouprem, gnoterem, bnotecount; + t_float stepdiv, rhythm, duration, beam, tied, step, rrest, tailon; + t_float objects, initobjects, groupobject, barlast; + t_float barnotes, barrests, barpos, restlen, lastdur; + t_float tempo, stavelen, fstavenum, group_id; + int stavenum; + t_float fractional, offset, initoffset, keyset, rested, prevrested, polyrhythm; + t_outlet *off, *rhy, *dur, *grp, *gcount, *tie, *bm, *rest, *rhyrest, *bar, *slave, *numer, *denom, *g_obj, *tail, *tuple, *bpm, *n_obj, *debugger, *groupid, *artic, *dyn;//, *stave; +} t_gemnotes_counter; + +void gemnotes_counter_bang(t_gemnotes_counter *z) +/* This function inserts a note at the current position, then makes any adjustments + * needed for the next beamgroups and bars etc. It also generates tie signals, + * and indicates whether tuples are being used */ +{ +// outlet_float(z->artic, z->articulation); +// z->articulation = 0; + z->gnoterem = z->grouprem / z->stepdiv; + float zpoly, polydiv; + int ipoly, gdiv, prevstave; + float chunk = z->step; + float thischunk, thatchunk, maxchunk, tail; + float prevnumer, prevdenom; + int i, j, x, y; + while(chunk > 0) + { +// z->rested = 0; + thischunk = z->gnoterem <= chunk ? z->gnoterem : chunk; + thischunk = thischunk > 32 ? 32 : thischunk; + chunk -= thischunk; + z->beam = z->groupcount > 0 && z->groupdiv >= 8 ? 1 : 0; + i = (int)thischunk; + for(j=0;j<6;j++) + { + x = gemnotes_counter_splits[j][i]; + if(x > 0) + { + /* prevstave = z->stavenum; + z->stavenum = (int)((z->allcount*z->allstep+z->offset) / z->stavelen); + z->fstavenum = (float)z->stavenum; + outlet_float(z->stave,z->fstavenum); + if(z->stavenum > prevstave) + { + z->objects = z->initobjects; + z->groupobject = z->objects; + z->groupnum -= z->groupcount; + z->groupcount = 0; + z->beam = 0; + z->allcount = 0; + } */ + z->tailon = z->grouprem <= z->step && z->rested == 1 || z->groupcount == z->groupnum - 1 && z->rested == 1 ? 1 : 0; + thischunk -= (float)x; + z->tied = chunk > 0 || thischunk > 0 ? 1 : 0; + + z->barlast = 0; + outlet_float(z->groupid,z->group_id); + outlet_float(z->n_obj, z->objects); + outlet_float(z->tuple, z->polyrhythm); + if(z->beam == 0) + { + z->groupobject = z->objects; + outlet_float(z->g_obj, z->objects); + } + outlet_float(z->artic, z->articulation); + z->articulation = 0; + outlet_float(z->tail, z->tailon); + z->objects++; + outlet_float(z->bm, z->beam); + outlet_float(z->tie, z->tied); + outlet_float(z->gcount, z->groupcount); + outlet_float(z->grp, z->groupnum); + outlet_float(z->dur, (float)x); + outlet_float(z->rhy, z->rhythm); + outlet_float(z->off, z->allcount*z->allstep+z->offset); + thatchunk = (float)x * z->stepdiv; + maxchunk = thatchunk > 16 ? 16 : thatchunk; + z->allcount += maxchunk; + z->barcount += thatchunk; + z->barrem -= thatchunk; + // z->barnotes += thatchunk; + z->groupcount += (float)x; + z->grouprem -= thatchunk; + z->lastdur = thatchunk; + z->prevrested = z->rested; + z->rested = 0; + } + } + if(z->barrem < 1 && z->allcount > 0 && z->barlast == 0) + { + z->group_id++; + z->barlast = 1; + outlet_float(z->groupid, z->group_id); + outlet_float(z->n_obj, z->objects); + // z->barpos += (z->barnotes + z->barrests) * z->allstep; + maxchunk = z->lastdur > 16 ? 16 : z->lastdur; + z->barpos = (z->allcount - (maxchunk / 2)) * z->allstep + z->offset; + // This is the alternative barpos method, if the other one can't be made to work. + z->objects++; + outlet_float(z->bar, z->barpos); + z->barnotes = z->barrests = 0; + if(z->nextnumer) + { + prevnumer = z->numerator; + prevdenom = z->denominator; + z->numerator = z->nextnumer; + if(z->nextdenom) + { + z->denominator = z->nextdenom; + } + if(z->numerator != prevnumer || z->denominator != prevdenom) + { + outlet_float(z->n_obj, z->objects); + z->objects++; + outlet_float(z->denom, z->denominator); + outlet_float(z->numer, z->numerator); + } + z->nextnumer = z->nextdenom = 0; + z->barlen = (64 / z->denominator) * z->numerator; + } + z->nowgroup = 0; + z->groupcount = 0; + z->barcount = 0; + z->groupnum = atom_getfloatarg(z->nowgroup, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup + 1, 128, z->groups); + z->polyrhythm = 0; + gdiv = (int)z->groupdiv; + if(gdiv != 64 && gdiv != 32 && gdiv != 16 && gdiv != 8 && gdiv != 4 && gdiv != 2 && gdiv != 1) + { + // polydiv = 1; + zpoly = z->groupdiv; + ipoly = (int)zpoly; + + for(i=0;i<7;i++) + { + // polydiv *= 0.5; + zpoly *= 0.5; + ipoly = (int)zpoly; + post("ipoly = %d, zpoly = %f",ipoly,zpoly); + if(fabs(zpoly - (float)ipoly) < 0.1) z->polyrhythm = zpoly; + } + } + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->grouplen; + z->rhythm = z->groupdiv >= 64 ? 64 : z->groupdiv >= 32 ? 32 : z->groupdiv >= 16 ? 16 : z->groupdiv >= 8 ? 8 : z->groupdiv >= 4 ? 4 : z->groupdiv >= 2 ? 2 : 1; + z->barrem = z->barlen; + } + else if(z->grouprem < 1) + { + z->group_id++; + outlet_float(z->groupid, z->group_id); + z->nowgroup = (z->nowgroup + 1) % z->numgroups; + z->groupcount = 0; + z->groupnum = atom_getfloatarg(z->nowgroup * 2, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup * 2 + 1, 128, z->groups); + z->polyrhythm = 0; + gdiv = (int)z->groupdiv; + if(gdiv != 64 && gdiv != 32 && gdiv != 16 && gdiv != 8 && gdiv != 4 && gdiv != 2 && gdiv != 1) + { + // polydiv = 1; + zpoly = z->groupdiv; + ipoly = (int)zpoly; + + for(i=0;i<7;i++) + { + // polydiv *= 0.5; + zpoly *= 0.5; + ipoly = (int)zpoly; + post("ipoly = %d, zpoly = %f",ipoly,zpoly); + if(fabs(zpoly - (float)ipoly) < 0.1) z->polyrhythm = zpoly; + } + } + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->grouplen; + z->rhythm = z->groupdiv >= 64 ? 64 : z->groupdiv >= 32 ? 32 : z->groupdiv >= 16 ? 16 : z->groupdiv >= 8 ? 8 : z->groupdiv >= 4 ? 4 : z->groupdiv >= 2 ? 2 : 1; + } + } + outlet_float(z->debugger, z->allcount*z->allstep+z->offset); +} + +void gemnotes_counter_float(t_gemnotes_counter *z, t_floatarg f) +/* this function inserts rests if the float is different from the current position, + * also a barline if the float is less than the current position within the bar. + * Otherwise it inserts a note at the current position if the float is the same (sic)*/ +{ + z->gnoterem = z->grouprem / z->stepdiv; + int i, j, x; + float fpos = f * z->stepdiv; + int ipoly, gdiv, prevstave; + float zpoly, polydiv; + float chunk, thischunk, thatchunk, maxchunk, prevnumer, prevdenom; + if(fpos != z->barcount) + { + if(fpos < z->barcount) + { + // z->beam = 0; + j = 0; + chunk = (z->barrem + fpos) / z->stepdiv; + z->barpos += ((z->barrem / z->stepdiv) * z->restlen + z->barnotes) * z->allstep; + while(chunk > 0) + { + z->barlast = 0; + thischunk = z->gnoterem <= chunk ? z->gnoterem : chunk; + thischunk = thischunk > 32 ? 32 : thischunk; + chunk -= thischunk; + i = (int)thischunk; + for(j=0;j<6;j++) + { + x = gemnotes_counter_splits[j][i]; + if(x > 0) + { + /* prevstave = z->stavenum; + z->stavenum = (int)((z->allcount*z->allstep+z->offset) / z->stavelen); + z->fstavenum = (float)z->stavenum; + outlet_float(z->stave,z->fstavenum); + if(z->stavenum > prevstave) + { + z->objects = z->initobjects; + z->groupobject = z->objects; + z->groupnum -= z->groupcount; + z->groupcount = 0; + z->allcount = 0; + } + if(z->rested == 0 && z->prevrested == 1) + { + z->tailon = z->groupobject; + outlet_float(z->tail, z->tailon); + } */ + z->prevrested = z->rested; + z->rested = 1; + outlet_float(z->n_obj, z->objects); + z->objects++; + outlet_float(z->tuple, z->polyrhythm); + outlet_float(z->rhyrest, z->rhythm); + outlet_float(z->dur, (float)x); + outlet_float(z->rest, z->allcount*z->allstep + z->offset); + thatchunk = (float)x * z->stepdiv; + z->allcount += thatchunk * z->restlen; + // z->barrests += thatchunk * z->restlen; + z->barcount += thatchunk; + z->barrem -= thatchunk; + z->groupcount += (float)x; + thischunk -= (float)x; + z->grouprem -= thatchunk; + z->lastdur = thatchunk * z->restlen; + z->rested = 1; + } + } + if(z->barrem < 1 && z->barlast == 0) //&& z->allcount > 0) + { + z->group_id++; + outlet_float(z->groupid, z->group_id); + outlet_float(z->n_obj, z->objects); + z->barlast = 1; + z->objects++; + maxchunk = z->lastdur > 16 ? 16 : z->lastdur; + z->barpos = (z->allcount - (maxchunk / 2)) * z->allstep + z->offset; + // z->barpos += (z->barnotes + z->barrests) * z->allstep; + outlet_float(z->bar, z->barpos); + z->barnotes = z->barrests = 0; + if(z->nextnumer) + { + prevnumer = z->numerator; + prevdenom = z->denominator; + z->numerator = z->nextnumer; + if(z->nextdenom) + { + z->denominator = z->nextdenom; + } + if(z->numerator != prevnumer || z->denominator != prevdenom) + { + outlet_float(z->n_obj, z->objects); + z->objects++; + outlet_float(z->denom, z->denominator); + outlet_float(z->numer, z->numerator); + } + z->nextnumer = z->nextdenom = 0; + z->barlen = (64 / z->denominator) * z->numerator; + } + + z->nowgroup = 0; + z->groupnum = atom_getfloatarg(z->nowgroup * 2, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup * 2 + 1, 128, z->groups); + z->stepdiv = 64 / z->groupdiv; + z->barcount = fpos * z->stepdiv; + z->barrem = z->barlen - z->barcount; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->groupnum - fpos; + if(z->grouprem <= 0) // a horrible kludge!!!recursion needed + { + z->nowgroup = (z->nowgroup + 1) % z->numgroups; + z->groupnum = atom_getfloatarg(z->nowgroup * 2, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup * 2 + 1, 128, z->groups); + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->groupnum - (0 - fpos); + if(z->grouprem <= 0) + { + z->nowgroup = (z->nowgroup + 1) % z->numgroups; + z->groupnum = atom_getfloatarg(z->nowgroup * 2, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup * 2 + 1, 128, z->groups); + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->groupnum - (0 - z->grouprem); + } + } + z->rhythm = z->groupdiv >= 64 ? 64 : z->groupdiv >= 32 ? 32 : z->groupdiv >= 16 ? 16 : z->groupdiv >= 8 ? 8 : z->groupdiv >= 4 ? 4 : z->groupdiv >= 2 ? 2 : 1; + z->groupcount = 0; + z->polyrhythm = 0; + gdiv = (int)z->groupdiv; + if(gdiv != 64 && gdiv != 32 && gdiv != 16 && gdiv != 8 && gdiv != 4 && gdiv != 2 && gdiv != 1) + { + // polydiv = 1; + zpoly = z->groupdiv; + ipoly = (int)zpoly; + + for(i=0;i<7;i++) + { + // polydiv *= 0.5; + zpoly *= 0.5; + ipoly = (int)zpoly; + post("ipoly = %d, zpoly = %f",ipoly,zpoly); + if(fabs(zpoly - (float)ipoly) < 0.1) z->polyrhythm = zpoly; + } + } + } + else if(z->grouprem < 1) + { + z->group_id++; + outlet_float(z->groupid, z->group_id); + z->nowgroup = (z->nowgroup + 1) % z->numgroups; + z->groupcount = 0; + z->groupnum = atom_getfloatarg(z->nowgroup * 2, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup * 2 + 1, 128, z->groups); + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->grouplen; + z->rhythm = z->groupdiv >= 64 ? 64 : z->groupdiv >= 32 ? 32 : z->groupdiv >= 16 ? 16 : z->groupdiv >= 8 ? 8 : z->groupdiv >= 4 ? 4 : z->groupdiv >= 2 ? 2 : 1; + z->polyrhythm = 0; + gdiv = (int)z->groupdiv; + if(gdiv != 64 && gdiv != 32 && gdiv != 16 && gdiv != 8 && gdiv != 4 && gdiv != 2 && gdiv != 1) + { + polydiv = 1; + zpoly = z->groupdiv; + ipoly = (int)zpoly; + + for(i=0;i<7;i++) + { + polydiv *= 0.5; + zpoly *= 0.5; + ipoly = (int)zpoly; + post("ipoly = %d, zpoly = %f",ipoly,zpoly); + if(fabs(zpoly - (float)ipoly) < 0.1) z->polyrhythm = zpoly; + } + } + } + } + } + else if(fpos > z->barcount) + { + z->beam = 0; + chunk = (fpos - z->barcount) / z->stepdiv; + while(chunk > 0) + { + thischunk = z->gnoterem <= chunk ? z->gnoterem : chunk; + thischunk = thischunk > 32 ? 32 : thischunk; + chunk -= thischunk; + i = (int)thischunk; + for(j=0;j<6;j++) + { + x = gemnotes_counter_splits[j][i]; + if(x > 0) + { + z->barlast = 0; + /* prevstave = z->stavenum; + z->stavenum = (int)((z->allcount*z->allstep+z->offset) / z->stavelen); + z->fstavenum = (float)z->stavenum; + outlet_float(z->stave,z->fstavenum); + if(z->stavenum > prevstave) + { + z->objects = z->initobjects; + z->groupobject = z->objects; + z->groupnum -= z->groupcount; + z->groupcount = 0; + z->allcount = 0; + } */ + if(z->rested == 0 && z->prevrested == 1) + { + z->tailon = z->groupobject; + outlet_float(z->tail, z->tailon); + } + z->prevrested = z->rested; + z->rested = 1; + outlet_float(z->groupid, z->group_id); + outlet_float(z->n_obj, z->objects); + z->objects++; + outlet_float(z->tuple, z->polyrhythm); + outlet_float(z->rhyrest, z->rhythm); + outlet_float(z->dur, (float)x); + outlet_float(z->rest, z->allcount*z->allstep + z->offset); + thatchunk = (float)x * z->stepdiv; + z->allcount += thatchunk * z->restlen; + // z->barrests += thatchunk * z->restlen; + z->barcount += thatchunk; + z->barrem -= thatchunk; + z->groupcount += (float)x; + thischunk -= (float)x; + z->grouprem -= thatchunk; + z->lastdur = thatchunk * z->restlen; + } + } + if(z->grouprem < 1) + { + z->group_id++; + outlet_float(z->groupid, z->group_id); + z->nowgroup = (z->nowgroup + 1) % z->numgroups; + z->groupcount = 0; + z->groupnum = atom_getfloatarg(z->nowgroup * 2, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup * 2 + 1, 128, z->groups); + z->polyrhythm = 0; + gdiv = (int)z->groupdiv; + if(gdiv != 64 && gdiv != 32 && gdiv != 16 && gdiv != 8 && gdiv != 4 && gdiv != 2 && gdiv != 1) + { + // polydiv = 1; + zpoly = z->groupdiv; + ipoly = (int)zpoly; + + for(i=0;i<7;i++) + { + // polydiv *= 0.5; + zpoly *= 0.5; + ipoly = (int)zpoly; + post("ipoly = %d, zpoly = %f",ipoly,zpoly); + if(fabs(zpoly - (float)ipoly) < 0.1) z->polyrhythm = zpoly; + } + } + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->grouplen; + z->rhythm = z->groupdiv >= 64 ? 64 : z->groupdiv >= 32 ? 32 : z->groupdiv >= 16 ? 16 : z->groupdiv >= 8 ? 8 : z->groupdiv >= 4 ? 4 : z->groupdiv >= 2 ? 2 : 1; + } + } + } + } +/* the entire "bang" routine */ + chunk = z->step; + while(chunk > 0) + { + thischunk = z->gnoterem <= chunk ? z->gnoterem : chunk; + thischunk = thischunk > 32 ? 32 : thischunk; + chunk -= thischunk; + /* if(z->rested == 1) + { + z->groupnum -= z->groupcount; + z->groupcount = 0; + } */ + z->beam = z->grouprem && z->groupcount > 0 && z->groupdiv >= 8 ? 1 : 0; + i = (int)thischunk; + for(j=0;j<6;j++) + { + x = gemnotes_counter_splits[j][i]; + if(x > 0) + { + /* prevstave = z->stavenum; + z->stavenum = (int)((z->allcount*z->allstep+z->offset) / z->stavelen); + z->fstavenum = (float)z->stavenum; + outlet_float(z->stave,z->fstavenum); + if(z->stavenum > prevstave) + { + z->objects = z->initobjects; + z->groupobject = z->objects; + z->groupnum -= z->groupcount; + z->groupcount = 0; + z->beam = 0; + z->allcount = 0; + } */ + z->tailon = z->grouprem <= z->step && z->rested == 1 || z->groupcount == z->groupnum - 1 && z->rested == 1 ? 1 : 0; + thischunk -= (float)x; + z->tied = chunk > 0 || thischunk > 0 ? 1 : 0; + + z->barlast = 0; + outlet_float(z->n_obj, z->objects); + outlet_float(z->tuple, z->polyrhythm); + if(z->beam == 0) + { + z->groupobject = z->objects; + outlet_float(z->g_obj, z->objects); + } + outlet_float(z->artic, z->articulation); + z->articulation = 0; + outlet_float(z->tail, z->tailon); + z->objects++; + outlet_float(z->bm, z->beam); + outlet_float(z->tie, z->tied); + outlet_float(z->gcount, z->groupcount); + outlet_float(z->grp, z->groupnum); + outlet_float(z->dur, (float)x); + outlet_float(z->rhy, z->rhythm); + outlet_float(z->off, z->allcount*z->allstep+z->offset); + thatchunk = (float)x * z->stepdiv; + maxchunk = thatchunk > 16 ? 16 : thatchunk; + z->allcount += maxchunk; + z->barcount += thatchunk; + z->barrem -= thatchunk; + // z->barnotes += thatchunk; + z->groupcount += (float)x; + z->grouprem -= thatchunk; + z->prevrested = z->rested; + z->rested = 0; + z->lastdur = thatchunk * z->restlen; + } + } + if(z->barrem < 1 && z->allcount > 0 && z->barlast == 0) + { + z->barlast = 1; + z->group_id++; + outlet_float(z->groupid, z->group_id); + outlet_float(z->n_obj, z->objects); + maxchunk = z->lastdur > 16 ? 16 : z->lastdur; + z->barpos = (z->allcount - (maxchunk / 2)) * z->allstep + z->offset; + // z->barpos += (z->barnotes + z->barrests) * z->allstep; + z->objects++; + outlet_float(z->bar, z->barpos); + z->barnotes = z->barrests = 0; + if(z->nextnumer) + { + prevnumer = z->numerator; + prevdenom = z->denominator; + z->numerator = z->nextnumer; + if(z->nextdenom) + { + z->denominator = z->nextdenom; + } + if(z->numerator != prevnumer || z->denominator != prevdenom) + { + outlet_float(z->n_obj, z->objects); + z->objects++; + outlet_float(z->denom, z->denominator); + outlet_float(z->numer, z->numerator); + } + z->nextnumer = z->nextdenom = 0; + z->barlen = (64 / z->denominator) * z->numerator; + } + z->nowgroup = 0; + z->groupcount = 0; + z->barcount = 0; + z->groupnum = atom_getfloatarg(z->nowgroup, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup + 1, 128, z->groups); + z->polyrhythm = 0; + gdiv = (int)z->groupdiv; + if(gdiv != 64 && gdiv != 32 && gdiv != 16 && gdiv != 8 && gdiv != 4 && gdiv != 2 && gdiv != 1) + { + // polydiv = 1; + zpoly = z->groupdiv; + ipoly = (int)zpoly; + + for(i=0;i<7;i++) + { + // polydiv *= 0.5; + zpoly *= 0.5; + ipoly = (int)zpoly; + post("ipoly = %d, zpoly = %f",ipoly,zpoly); + if(fabs(zpoly - (float)ipoly) < 0.1) z->polyrhythm = zpoly; + } + } + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->grouplen; + z->rhythm = z->groupdiv >= 64 ? 64 : z->groupdiv >= 32 ? 32 : z->groupdiv >= 16 ? 16 : z->groupdiv >= 8 ? 8 : z->groupdiv >= 4 ? 4 : z->groupdiv >= 2 ? 2 : 1; + z->barrem = z->barlen; + } + else if(z->grouprem < 1) + { + z->group_id++; + outlet_float(z->groupid, z->group_id); + + z->nowgroup = (z->nowgroup + 1) % z->numgroups; + z->groupcount = 0; + z->groupnum = atom_getfloatarg(z->nowgroup * 2, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup * 2 + 1, 128, z->groups); + z->polyrhythm = 0; + gdiv = (int)z->groupdiv; + if(gdiv != 64 && gdiv != 32 && gdiv != 16 && gdiv != 8 && gdiv != 4 && gdiv != 2 && gdiv != 1) + { + // polydiv = 1; + zpoly = z->groupdiv; + ipoly = (int)zpoly; + + for(i=0;i<7;i++) + { + // polydiv *= 0.5; + zpoly *= 0.5; + ipoly = (int)zpoly; + post("ipoly = %d, zpoly = %f",ipoly,zpoly); + if(fabs(zpoly - (float)ipoly) < 0.1) z->polyrhythm = zpoly; + } + } + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->grouplen; + z->rhythm = z->groupdiv >= 64 ? 64 : z->groupdiv >= 32 ? 32 : z->groupdiv >= 16 ? 16 : z->groupdiv >= 8 ? 8 : z->groupdiv >= 4 ? 4 : z->groupdiv >= 2 ? 2 : 1; + } + } + outlet_float(z->debugger, z->allcount*z->allstep+z->offset); +} + +void gemnotes_counter_bar(t_gemnotes_counter *z, t_symbol *s, int argc, t_atom *argv) +{ + z->gnoterem = z->grouprem / z->stepdiv; + int i, j, x, y, ipoly; + int scope = (int)((float)argc * 0.5); + // post("scope = %d", scope); + float chunk, thischunk, thatchunk, maxchunk, zpoly; + float num, div, prevnumer, prevdenom; + j = 0; + // make a rests function for a whole bar, or the rest of the bar, and a barline; + chunk = z->barrem / z->stepdiv; + // post("chunk = %f",chunk); + z->barpos += (z->barnotes + ((z->barrem / z->stepdiv) * z->restlen) * z->allstep); + if(z->allcount > 0) + { + /* while(chunk > 0) + { + thischunk = z->gnoterem <= chunk ? z->gnoterem : chunk; + thischunk = thischunk > 32 ? 32 : thischunk; + chunk -= thischunk; + i = (int)thischunk; + // post("i = %d",i); + + for(j=0;j<6;j++) + { + x = gemnotes_counter_splits[j][i]; + // post("x = %d",x); + if(x > 0) + { + if(z->rested == 0 && z->objects == z->groupobject) + { + z->tailon = z->groupobject; + outlet_float(z->tail, z->tailon); + } + z->rested = 1; + outlet_float(z->n_obj, z->objects); + z->objects++; + outlet_float(z->tuple, z->polyrhythm); + outlet_float(z->rhyrest, z->rhythm); + outlet_float(z->dur, (float)x); + outlet_float(z->rest, z->allcount*z->allstep + z->offset); + + thatchunk = (float)x * z->stepdiv; + z->allcount += thatchunk * z->restlen; + z->barcount += thatchunk; + z->barrem -= thatchunk; + z->groupcount += (float)x; + thischunk -= (float)x; + z->grouprem -= thatchunk; + } + } + } */ + if(z->barlast == 0) + { + z->barlast = 1; + outlet_float(z->n_obj, z->objects); + z->objects++; + maxchunk = z->lastdur > 16 ? 16 : z->lastdur; + z->barpos = (z->allcount - (maxchunk / 2)) * z->allstep + z->offset; + outlet_float(z->bar, z->barpos); + z->barnotes = z->barrests = 0; + } + } + if(argc) + { + prevnumer = z->numerator; + prevdenom = z->denominator; + z->numerator = atom_getfloat(argv); + if(argc > 1) + { + z->denominator = atom_getfloat(argv+1); + z->numgroups = 0; + if(scope > 1) + { + for(i = 0;i < scope - 1;i++) + { + j = i + 1; + num = atom_getfloat(argv+(j*2)); + div = atom_getfloat(argv+(j*2+1)); + SETFLOAT(&z->groups[i*2],num); + SETFLOAT(&z->groups[i*2+1],div); + z->numgroups++; + } + } + } + if(z->numerator != prevnumer || z->denominator != prevdenom || z->allcount == 0) + { + outlet_float(z->n_obj, z->objects); + z->objects++; + outlet_float(z->denom, z->denominator); + outlet_float(z->numer, z->numerator); + } + z->barlen = (64 / z->denominator) * z->numerator; + } + z->nowgroup = 0; + z->groupcount = 0; + z->barcount = 0; + z->groupnum = atom_getfloatarg(z->nowgroup * 2, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup * 2 + 1, 128, z->groups); + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->grouplen; + z->rhythm = z->groupdiv >= 64 ? 64 : z->groupdiv >= 32 ? 32 : z->groupdiv >= 16 ? 16 : z->groupdiv >= 8 ? 8 : z->groupdiv >= 4 ? 4 : z->groupdiv >= 2 ? 2 : 1; + z->barrem = z->barlen; + outlet_float(z->debugger, z->allcount*z->allstep+z->offset); +} + +void gemnotes_counter_articulation(t_gemnotes_counter *z, t_floatarg art) +{ + z->articulation = art; +} + +void gemnotes_counter_dyn(t_gemnotes_counter *z, t_symbol *s, int argc, t_atom *argv) +{ + float terraced = 0; + float dynfirst = 0; + float dynlen = 0; + float dynlast = 0; + float hairpin = 0; + switch(argc) + // outlet_list(x->mapout, gensym("list"), x->max+1, x->x_map.nomap); + + { + case 1: + terraced = atom_getfloat(argv); + SETFLOAT(&z->terrace[0], z->allcount*z->allstep+z->offset); + SETFLOAT(&z->terrace[1], terraced); + outlet_float(z->n_obj, z->objects); + z->objects++; + outlet_list(z->dyn, gensym("list"), 2, z->terrace); + break; + case 3: + dynfirst = atom_getfloat(argv); + dynlen = atom_getfloat(argv+1) * z->stepdiv * z->allstep; + dynlast = atom_getfloat(argv+2); + hairpin = dynfirst > dynlast ? 0 : 1; + SETFLOAT(&z->dynamics[0], z->allcount*z->allstep+z->offset); + SETFLOAT(&z->dynamics[1], dynfirst); + SETFLOAT(&z->dynamics[2], dynlen); + SETFLOAT(&z->dynamics[3], dynlast); + SETFLOAT(&z->dynamics[4], hairpin); //bt + outlet_float(z->n_obj, z->objects); + z->objects++; + outlet_list(z->dyn, gensym("list"), 5, z->dynamics); +// outlet_float(z->off, z->allcount*z->allstep+z->offset); + break; + default: + break; + } +} + +// new method 6-1-11 +void gemnotes_counter_groups(t_gemnotes_counter *z, t_symbol *s, int argc, t_atom *argv) +{ + float argc2 = (float)argc * 0.5; + int iargc2 = (int)argc2; + int i,j,k; + z->numgroups = iargc2; + j = 0; + k = 0; + float num, div; + num = 4; + div = 16; + if(iargc2) + { + for(i=0;igroups[j],num); + SETFLOAT(&z->groups[k],div); + } + if((float)iargc2 < argc2) + { + z->numgroups++; + num = atom_getfloat(argv+(argc-1)); + SETFLOAT(&z->groups[j],num); + SETFLOAT(&z->groups[k],div); + } + } + else if(argc2) + { + num = atom_getfloat(argv); + div = 16; + SETFLOAT(&z->groups[j],num); + SETFLOAT(&z->groups[k],div); + } + z->nowgroup = 0; + z->groupcount = 0; + z->groupnum = atom_getfloatarg(z->nowgroup * 2, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup * 2 + 1, 128, z->groups); + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->grouplen; + z->rhythm = z->groupdiv >= 64 ? 64 : z->groupdiv >= 32 ? 32 : z->groupdiv >= 16 ? 16 : z->groupdiv >= 8 ? 8 : z->groupdiv >= 4 ? 4 : z->groupdiv >= 2 ? 2 : 1; +} + +void gemnotes_counter_group(t_gemnotes_counter *z, t_floatarg f1, t_floatarg f2) +{ + int ipoly, gdiv, i; + float zpoly, polydiv; + if(f1 && f2) + { + z->groupcount = 0; + z->groupnum = f1; + z->groupdiv = f2; + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->grouplen; + z->rhythm = z->groupdiv >= 64 ? 64 : z->groupdiv >= 32 ? 32 : z->groupdiv >= 16 ? 16 : z->groupdiv >= 8 ? 8 : z->groupdiv >= 4 ? 4 : z->groupdiv >= 2 ? 2 : 1; + z->polyrhythm = 0; + gdiv = z->groupdiv; + z->group_id++; + outlet_float(z->groupid, z->group_id); + if(gdiv != 64 && gdiv != 32 && gdiv != 16 && gdiv != 8 && gdiv != 4 && gdiv != 2 && gdiv != 1) + { + // polydiv = 1; + zpoly = z->groupdiv; + ipoly = (int)zpoly; + + for(i=0;i<7;i++) + { + // polydiv *= 0.5; + zpoly *= 0.5; + ipoly = (int)zpoly; + post("ipoly = %d, zpoly = %f",ipoly,zpoly); + if(fabs(zpoly - (float)ipoly) < 0.1) z->polyrhythm = zpoly; + } + } + } +} + +void gemnotes_counter_rest(t_gemnotes_counter *z, t_symbol *s, int argc, t_atom *argv) +{ + z->gnoterem = z->grouprem / z->stepdiv; + + float chunk, thischunk, thatchunk, prevnumer, prevdenom; + int i, j, x; + float zpoly, polydiv; + int ipoly, gdiv, prevstave; + float rdur = argc > 0 ? atom_getfloat(argv) : z->step; + z->restlen = argc > 1 ? atom_getfloat(argv+1) : z->restlen; + if(rdur > 0) + { + if(z->rested == 0 && z->prevrested == 1) + { + z->tailon = z->groupobject; + outlet_float(z->tail, z->tailon); + } + z->beam = 0; + j = 0; + chunk = rdur; + while(chunk > 0) + { + thischunk = z->gnoterem <= chunk ? z->gnoterem : chunk; + thischunk = thischunk > 32 ? 32 : thischunk; + chunk -= thischunk; + i = (int)thischunk; + x = gemnotes_counter_splits[j][i]; + if(x > 0) + { + /* prevstave = z->stavenum; + z->stavenum = (int)((z->allcount*z->allstep+z->offset) / z->stavelen); + z->fstavenum = (float)z->stavenum; + outlet_float(z->stave,z->fstavenum); + if(z->stavenum > prevstave) + { + z->objects = z->initobjects; + z->groupobject = z->objects; + outlet_float(z->g_obj, z->objects); + z->allcount = 0; + } */ + z->barlast = 0; + outlet_float(z->n_obj, z->objects); + z->objects++; + outlet_float(z->tuple, z->polyrhythm); + outlet_float(z->rhyrest, z->rhythm); + outlet_float(z->dur, (float)x); + outlet_float(z->rest, z->allcount*z->allstep+z->offset); + thatchunk = (float)x * z->stepdiv; + z->allcount += thatchunk * z->restlen; + z->lastdur = thatchunk * z->restlen; + // z->barrests += thatchunk * z->restlen; + z->barcount += thatchunk; + z->barrem -= thatchunk; + z->groupcount += (float)x; + thischunk -= (float)x; + z->grouprem -= thatchunk; + z->prevrested = z->rested; + z->rested = 1; + } + if(z->barrem < 1 && z->barlast == 0) + { + z->barlast = 1; + outlet_float(z->n_obj, z->objects); + // z->barpos += (z->barnotes + z->barrests) * z->allstep; + z->barpos = (z->allcount - (z->lastdur / 2)) * z->allstep + z->offset; + z->objects++; + outlet_float(z->bar, z->barpos); + z->barnotes = z->barrests = 0; + if(z->nextnumer) + { + prevnumer = z->numerator; + prevdenom = z->denominator; + z->numerator = z->nextnumer; + if(z->nextdenom) + { + z->denominator = z->nextdenom; + } + if(z->numerator != prevnumer || z->denominator != prevdenom) + { + outlet_float(z->n_obj, z->objects); + z->objects++; + outlet_float(z->denom, z->denominator); + outlet_float(z->numer, z->numerator); + } + z->nextnumer = z->nextdenom = 0; + z->barlen = (64 / z->denominator) * z->numerator; + } + + z->nowgroup = 0; + z->groupcount = 0; + z->barcount = 0; + z->groupnum = atom_getfloatarg(z->nowgroup, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup + 1, 128, z->groups); + z->polyrhythm = 0; + gdiv = z->groupdiv; + if(gdiv != 64 && gdiv != 32 && gdiv != 16 && gdiv != 8 && gdiv != 4 && gdiv != 2 && gdiv != 1) + { + // polydiv = 1; + zpoly = z->groupdiv; + ipoly = (int)zpoly; + + for(i=0;i<7;i++) + { + // polydiv *= 0.5; + zpoly *= 0.5; + ipoly = (int)zpoly; + post("ipoly = %d, zpoly = %f",ipoly,zpoly); + if(fabs(zpoly - (float)ipoly) < 0.1) z->polyrhythm = zpoly; + } + } + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->grouplen; + z->rhythm = z->groupdiv >= 64 ? 64 : z->groupdiv >= 32 ? 32 : z->groupdiv >= 16 ? 16 : z->groupdiv >= 8 ? 8 : z->groupdiv >= 4 ? 4 : z->groupdiv >= 2 ? 2 : 1; + z->barrem = z->barlen; + } + else if(z->grouprem < 1) + { + z->nowgroup = (z->nowgroup + 1) % z->numgroups; + z->groupcount = 0; + z->groupnum = atom_getfloatarg(z->nowgroup * 2, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup * 2 + 1, 128, z->groups); + z->polyrhythm = 0; + gdiv = z->groupdiv; + if(gdiv != 64 && gdiv != 32 && gdiv != 16 && gdiv != 8 && gdiv != 4 && gdiv != 2 && gdiv != 1) + { + // polydiv = 1; + zpoly = z->groupdiv; + ipoly = (int)zpoly; + + for(i=0;i<7;i++) + { + // polydiv *= 0.5; + zpoly *= 0.5; + ipoly = (int)zpoly; + post("ipoly = %d, zpoly = %f",ipoly,zpoly); + if(fabs(zpoly - (float)ipoly) < 0.1) z->polyrhythm = zpoly; + } + } + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->grouplen; + z->rhythm = z->groupdiv >= 64 ? 64 : z->groupdiv >= 32 ? 32 : z->groupdiv >= 16 ? 16 : z->groupdiv >= 8 ? 8 : z->groupdiv >= 4 ? 4 : z->groupdiv >= 2 ? 2 : 1; + } + } + } + outlet_float(z->debugger, z->allcount*z->allstep+z->offset); +} + +void gemnotes_counter_nextbar(t_gemnotes_counter *z, t_symbol *s, int argc, t_atom *argv) +{ + if(argc) + { + z->nextnumer = atom_getfloat(argv); + if(argc > 1) z->nextdenom = atom_getfloat(argv+1); + else z->nextdenom = z->denominator; + } +} + +void gemnotes_counter_tempo(t_gemnotes_counter *z, t_symbol *s, int argc, t_atom *argv) +{ + float thisoffset, thisbpm, thisrhythm, thatbpm, thatrhythm; + thisrhythm = 4; + thisoffset = z->allcount*z->allstep; + if(argc) + { + thisbpm = atom_getfloat(argv); + if(argc > 1) + { + thisrhythm = atom_getfloat(argv+1); + } + // else thisrhythm = atom_getfloatarg(1,2,z->temposign); + // thatbpm = atom_getfloatarg(0,2,z->temposign); + // thatrhythm = atom_getfloatarg(1,2,z->temposign); + // if(thisbpm != thatbpm || thisrhythm != thatrhythm) + // { + outlet_float(z->n_obj, z->objects); + z->objects++; + // if(z->allcount == 0) + SETFLOAT(&z->temposign[0],thisoffset); + // else if (z->allcount > 0) SETFLOAT(&z->temposign[0],z->allcount*z->allstep+z->offset); + SETFLOAT(&z->temposign[1],thisbpm); + SETFLOAT(&z->temposign[2],thisrhythm); + outlet_list(z->bpm, gensym("list"), 3, z->temposign); + // } + } + post("thisoffset = %f", thisoffset); +} + +void gemnotes_counter_debug(t_gemnotes_counter *z, t_floatarg f) +{ + post("numer = %d,denom = %d,groupnum = %d,groupdiv = %d",(int)z->numerator,(int)z->denominator,(int)z->groupnum,(int)z->groupdiv); + post("allcount = %d, barcount = %d, groupcount = %d",(int)z->allcount,(int)z->barcount,(int)z->groupcount); + post("barlen = %d,barrem = %d,grouplen = %d,grouprem = %d",(int)z->barlen,(int)z->barrem,(int)z->grouplen,(int)z->grouprem); + int i = f; + int j, x; + for(j=0;j<6;j++) + { + x = gemnotes_counter_splits[j][i]; + post("j = %d, i = %d, x = %d",j,i,x); + } +} + +void gemnotes_counter_step(t_gemnotes_counter *z, t_floatarg f) +{ + z->step = f; + z->fractional = ((int)(z->step * 100) % 100) != 0 ? 1 : 0; +} + +void gemnotes_counter_offset(t_gemnotes_counter *z, t_floatarg f) +{ + if(f) + { + z->offset += f; + } + else if(!f) + { + z->offset = z->initoffset; + } +} + +void gemnotes_counter_chord(t_gemnotes_counter *z) +{ + outlet_float(z->artic, z->articulation); + z->articulation = 0; + outlet_float(z->n_obj, z->objects); + z->objects++; + outlet_bang(z->slave); +} + +void gemnotes_counter_hdsq(t_gemnotes_counter *z, t_floatarg f) +{ + if(f) + { + z->offset += z->allcount * z->allstep; + z->allstep = f; + z->allcount = 0; + } + else if(!f) + { + z->offset += z->allcount * z->allstep; + z->allstep = 0.15; + z->allcount = 0; + } +} + +void gemnotes_counter_reset(t_gemnotes_counter *z) +{ + int gdiv, ipoly, i; + float zpoly, polydiv; + z->group_id = 0; + z->allcount = 0; + z->nowgroup = 0; + z->groupcount = 0; + z->barcount = 0; + z->barnotes = z->barrests = z->barpos = 0; + z->offset = z->initoffset; + z->objects = z->initobjects; + z->groupnum = atom_getfloatarg(z->nowgroup * 2, 128, z->groups); + z->groupdiv = atom_getfloatarg(z->nowgroup * 2 + 1, 128, z->groups); + z->polyrhythm = 0; + gdiv = z->groupdiv; + if(gdiv != 64 && gdiv != 32 && gdiv != 16 && gdiv != 8 && gdiv != 4 && gdiv != 2 && gdiv != 1) + { + polydiv = 1; + zpoly = z->groupdiv; + ipoly = (int)zpoly; + + for(i=0;i<7;i++) + { + polydiv *= 0.5; + zpoly *= 0.5; + ipoly = (int)zpoly; + if(fabs(zpoly - (float)ipoly) < 0.1) z->polyrhythm = zpoly; + } + } + z->stepdiv = 64 / z->groupdiv; + z->grouplen = z->groupnum * z->stepdiv; + z->grouprem = z->grouplen; + z->rhythm = z->groupdiv >= 64 ? 64 : z->groupdiv >= 32 ? 32 : z->groupdiv >= 16 ? 16 : z->groupdiv >= 8 ? 8 : z->groupdiv >= 4 ? 4 : z->groupdiv >= 2 ? 2 : 1; + z->barrem = z->barlen; + // z->stavenum = 0; + // outlet_float(z->stave,0); + outlet_float(z->debugger, z->allcount); +} + +void *gemnotes_counter_new(t_symbol *s, int argc, t_atom *argv) +{ + t_gemnotes_counter *z = (t_gemnotes_counter *)pd_new(gemnotes_counter_class); + int i; + for(i=0;i<128;i++) + { + SETFLOAT(&z->groups[i],0); + } + SETFLOAT(&z->groups[0],4); + SETFLOAT(&z->groups[1],16); + + SETFLOAT(&z->temposign[0],0); + SETFLOAT(&z->temposign[1],120); + SETFLOAT(&z->temposign[2],4); + + z->group_id = 0; + z->numgroups = 1; + z->nowgroup = 0; + // z->lastgroup = 0; + z->stepdiv = 4; + z->allstep = 0.15; + z->allcount = z->barcount = z->groupcount = 0; + z->step = 1; + z->barrem = z->barlen = 48; + + z->grouprem = z->grouplen = 16; + z->groupnum = 4; + z->groupdiv = 16; + + z->barnotes = 0; + z->barrests = 0; + z->barpos = 0; + z->barlast = 0; + z->restlen = 0.5; + + z->beam = z->tied = 0; + z->rhythm = 16; + + z->numerator = argc > 0 ? atom_getfloat(argv) : 3; + z->denominator = argc > 1 ? atom_getfloat(argv+1) : 4; + z->nextnumer = z->nextdenom = 0; + + z->initobjects = argc > 2 ? atom_getfloat(argv+2) : 0; + z->objects = z->initobjects; + z->initoffset = argc > 3 ? atom_getfloat(argv+3) : 0; + z->offset = z->initoffset; + z->groupobject = -1; + z->stavelen = argc > 4 ? atom_getfloat(argv+4) : 18; + z->stavenum = 0; + z->fstavenum = 0; + z->articulation = 0; + + z->off = outlet_new(&z->x_obj, gensym("float")); + z->rhy = outlet_new(&z->x_obj, gensym("float")); + z->dur = outlet_new(&z->x_obj, gensym("float")); + z->grp = outlet_new(&z->x_obj, gensym("float")); + z->gcount = outlet_new(&z->x_obj, gensym("float")); + z->tie = outlet_new(&z->x_obj, gensym("float")); + z->bm = outlet_new(&z->x_obj, gensym("float")); + z->rest = outlet_new(&z->x_obj, gensym("float")); + z->rhyrest = outlet_new(&z->x_obj, gensym("float")); + z->bar = outlet_new(&z->x_obj, gensym("float")); + z->slave = outlet_new(&z->x_obj, gensym("bang")); + z->numer = outlet_new(&z->x_obj, gensym("float")); + z->denom = outlet_new(&z->x_obj, gensym("float")); + z->tail = outlet_new(&z->x_obj, gensym("float")); + z->tuple = outlet_new(&z->x_obj, gensym("float")); + z->bpm = outlet_new(&z->x_obj, gensym("list")); + z->g_obj = outlet_new(&z->x_obj, gensym("float")); + z->n_obj = outlet_new(&z->x_obj, gensym("float")); + z->debugger = outlet_new(&z->x_obj, gensym("float")); + z->groupid = outlet_new(&z->x_obj, gensym("float")); + z->artic = outlet_new(&z->x_obj, gensym("float")); + z->dyn = outlet_new(&z->x_obj, gensym("list")); + // z->stave = outlet_new(&z->x_obj, gensym("float")); + return(void *)z; +} + +void gemnotes_counter_setup(void) +{ + gemnotes_counter_class = class_new(gensym("gemnotes_counter"), + (t_newmethod)gemnotes_counter_new, + 0, sizeof(t_gemnotes_counter), + 0, A_GIMME, 0); + post("gemnotes_counter - segmented all / bar / beamgroup counter..."); + post("...for dynamic object creation of musical scores."); + post("version 0.6...by Ed Kelly 2012 - morph_2016@yahoo.co.uk"); + + class_addbang(gemnotes_counter_class, gemnotes_counter_bang); + class_addfloat(gemnotes_counter_class, gemnotes_counter_float); + class_addmethod(gemnotes_counter_class, (t_method)gemnotes_counter_step, gensym("step"), A_DEFFLOAT, 0); + class_addmethod(gemnotes_counter_class, (t_method)gemnotes_counter_reset, gensym("reset"), A_DEFFLOAT, 0); + class_addmethod(gemnotes_counter_class, (t_method)gemnotes_counter_offset, gensym("offset"), A_DEFFLOAT, 0); + class_addmethod(gemnotes_counter_class, (t_method)gemnotes_counter_hdsq, gensym("hdsq"), A_DEFFLOAT, 0); + class_addmethod(gemnotes_counter_class, (t_method)gemnotes_counter_chord, gensym("chord"), A_DEFFLOAT, 0); + class_addmethod(gemnotes_counter_class, (t_method)gemnotes_counter_rest, gensym("rest"), A_GIMME, 0); + class_addmethod(gemnotes_counter_class, (t_method)gemnotes_counter_bar, gensym("bar"), A_GIMME, 0); + class_addmethod(gemnotes_counter_class, (t_method)gemnotes_counter_tempo, gensym("tempo"), A_GIMME, 0); + class_addmethod(gemnotes_counter_class, (t_method)gemnotes_counter_group, gensym("group"), A_DEFFLOAT, A_DEFFLOAT, 0); + class_addmethod(gemnotes_counter_class, (t_method)gemnotes_counter_debug, gensym("debug"), A_DEFFLOAT, 0); + class_addmethod(gemnotes_counter_class, (t_method)gemnotes_counter_nextbar, gensym("nextbar"), A_GIMME, 0); + class_addmethod(gemnotes_counter_class, (t_method)gemnotes_counter_dyn, gensym("dyn"), A_GIMME, 0); + class_addmethod(gemnotes_counter_class, (t_method)gemnotes_counter_articulation, gensym("articulation"), A_DEFFLOAT, 0); +} diff --git a/gemnotes_0.2.3/src/polyquant-help.pd b/gemnotes_0.2.3/src/polyquant-help.pd new file mode 100755 index 0000000..87de60f --- /dev/null +++ b/gemnotes_0.2.3/src/polyquant-help.pd @@ -0,0 +1,61 @@ +#N canvas 0 0 655 328 10; +#X text 286 48 creation arguments: tempo polyrhythm-depth; +#X text 294 92 depth 1: half \, quarter \, eighth notes etc; +#X text 294 105 depth 2: + triplets; +#X text 294 118 depth 3: + triplets and quintuplets; +#X text 294 132 depth 4: + triplets \, quintuplets and septuplets; +#X text 302 12 polyquant is a polyrhythmic quantizer; +#X text 294 148 and so on \, adding 11th \, 13th \, 17th \, 19th \, +23rd \, 29th \, 31th \, 37th \, 41th \, 43th \, 47th \, 53th \, 59th +and 61th divisions of the beat; +#X obj 66 88 timer; +#X floatatom 66 252 5 0 0 1 time - -; +#X floatatom 95 236 5 0 0 1 division - -; +#X floatatom 124 221 5 0 0 1 number - -; +#X floatatom 153 206 5 0 0 1 sign - -; +#X obj 66 187 polyquant 140 4; +#X obj 66 67 t b b; +#X obj 52 38 metro 200; +#X floatatom 66 110 5 0 0 0 - - -; +#X text 294 63 tempo is in beats-per-minute; +#X obj 52 14 loadbang; +#X msg 114 103 mode \$1; +#X obj 114 84 hradio 15 1 0 3 empty empty empty 0 -8 0 10 -262144 -1 +-1 1; +#X floatatom 173 116 5 1 18 2 polyrhythmic_depth - -; +#X text 295 77 polyrhythm depth is explained below; +#X obj 116 28 random 1800; +#X text 272 202 sign: -1 means the input time is less than the output +time \, 1 means the input time is greater than the output time; +#X text 272 229 number: number of notes of division value of the quantized +output; +#X text 272 257 division: division of the beat (8th \, 16th \, 6th +\, 20th etc); +#X text 272 275 time: quantized time value; +#X obj 116 50 + 50; +#X msg 173 132 plimit \$1; +#X text 162 64 0 = both; +#X text 162 75 1 = always lengthen; +#X text 162 86 2 = always shorten; +#X text 131 69 MODE:; +#X floatatom 240 136 5 60 180 2 BPM - -; +#X msg 240 152 bpm \$1; +#X connect 7 0 15 0; +#X connect 12 0 8 0; +#X connect 12 1 9 0; +#X connect 12 2 10 0; +#X connect 12 3 11 0; +#X connect 13 0 7 0; +#X connect 13 1 7 1; +#X connect 13 1 22 0; +#X connect 14 0 13 0; +#X connect 15 0 12 0; +#X connect 17 0 14 0; +#X connect 18 0 12 0; +#X connect 19 0 18 0; +#X connect 20 0 28 0; +#X connect 22 0 27 0; +#X connect 27 0 14 1; +#X connect 28 0 12 0; +#X connect 33 0 34 0; +#X connect 34 0 12 0; diff --git a/gemnotes_0.2.3/src/polyquant.c b/gemnotes_0.2.3/src/polyquant.c new file mode 100755 index 0000000..4d79e3b --- /dev/null +++ b/gemnotes_0.2.3/src/polyquant.c @@ -0,0 +1,178 @@ +/* + * polyquant: polyrhythmic notelength parser + * Copyright (C) 2010 edward kelly + * + * This software is BSD licensed. See LICENSE.txt for more details + */ + +#include "m_pd.h" +#include + +t_class *polyquant_class; + +typedef struct _polyquant { + t_object x_obj; + float dmatrix[18][9]; + float tmatrix[18][9][64]; + t_float bpm, qtime, wtime, plimit, dlimit, mode, sim_win, sim_sign, simile, bestsim, bestdiv, besttime, bestnum, bestsign, startoff, startnow; + t_outlet *time, *div, *num, *sign;//, *sta; +} t_polyquant; + +static float primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61}; + +void polyquant_float(t_polyquant *x, t_floatarg f) { + int i, j, k; + float sim_min; + x->bestsim = 0; + // x->sim_win = x->sim_win > 0 ? x->sim_win : 0.01; /* defaults to 0.01 so that we avoid /0 errors */ + for(i = 0;i < x->plimit;i++) { + for(j = x->dlimit;j < 9;j++) { + for(k=0;k<64;k++) { + float tvalue = x->tmatrix[i][j][k]; + sim_min = (f > tvalue) ? (f - tvalue) : (tvalue - f); + x->sim_sign = (f >= tvalue) ? 1 : -1; + x->simile = 1 / ((sim_min / x->sim_win) + 1); + if(x->mode == 0) { + if(x->simile >= x->bestsim){ + x->bestsim = x->simile; + x->bestdiv = x->dmatrix[i][j]; + x->besttime = tvalue; + x->bestnum = (float)k+1; + x->bestsign = x->sim_sign; + } + } + else if(x->mode == 1) { + if(x->simile >= x->bestsim && x->sim_sign == -1){ + x->bestsim = x->simile; + x->bestdiv = x->dmatrix[i][j]; + x->besttime = tvalue; + x->bestnum = (float)k+1; + x->bestsign = x->sim_sign; + } + } + else if(x->mode == 2) { + if(x->simile >= x->bestsim && x->sim_sign == 1){ + x->bestsim = x->simile; + x->bestdiv = x->dmatrix[i][j]; + x->besttime = tvalue; + x->bestnum = (float)k+1; + x->bestsign = x->sim_sign; + } + } + } + } + //so...the start time quantized, and then the quantized start becomes 0 + //so that the duration alone is quantized. + //build it into the gemnotes_counter, so that you can make a gemnotes_counter_live + } + outlet_float(x->sign, x->bestsign); + outlet_float(x->num, x->bestnum); + outlet_float(x->div, x->bestdiv); + outlet_float(x->time, x->besttime); +} + +/* + * The rarity of vintage instruments is a musician's cartel + */ + +void polyquant_bang(t_polyquant *x) { + outlet_float(x->sign, x->bestsign); + outlet_float(x->num, x->bestnum); + outlet_float(x->div, x->bestdiv); + outlet_float(x->time, x->besttime); +} + +void polyquant_bpm(t_polyquant *x, t_floatarg f) { + x->bpm = f > 0 ? f : 120; + x->qtime = 60000/x->bpm; + x->wtime = 4 * x->qtime; +} + +void polyquant_plimit(t_polyquant *x, t_floatarg f) { + x->plimit = f < 1 ? 1 : f > 18 ? 18 : f; +} + +void polyquant_dlimit(t_polyquant *x, t_floatarg f) { + x->dlimit = f < 0 ? 0 : f > 8 ? 8 : f; +} + +void polyquant_mode(t_polyquant *x, t_floatarg f) { + x->mode = f < 0 ? 0 : f > 2 ? 2 : f; +} + +void polyquant_win(t_polyquant *x, t_floatarg f) { + x->sim_win = f > 0 ? f : 10; +} + +void *polyquant_new(t_floatarg ibpm, t_floatarg flim) +{ + t_polyquant *x = (t_polyquant *)pd_new(polyquant_class); + x->mode = 0; + x->bpm = ibpm > 0 ? ibpm : 120; + x->qtime = 60000 / x->bpm; + x->wtime = x->qtime * 4; + x->plimit = flim < 1 ? 1 : flim > 18 ? 18 : flim; + x->dlimit = 4; + x->sim_win = 10; + x->time = outlet_new(&x->x_obj, gensym("float")); + x->div = outlet_new(&x->x_obj, gensym("float")); + x->num = outlet_new(&x->x_obj, gensym("float")); + x->sign = outlet_new(&x->x_obj, gensym("float")); + + int i, j, k; + float div, time; + //init dmatrix + for(i=0;i<18;i++) { + for(j=0;j<9;j++) { + x->dmatrix[i][j] = 0; + } + } + + j = 0; + div = 0; + for(i=0;i<18;i++) { + div = primes[i]; + while(div<=128) { + div *= 2; + } + x->dmatrix[i][0] = div; + while(div>=1) { + j++; + div *= 0.5; + x->dmatrix[i][j] = div; + } + } + //init tmatrix + for(i=0;i<18;i++) { + for(j=0;j<9;j++) { + div = x->dmatrix[i][j]; + if(div>0) { + k = 0; + time = x->wtime / div; + for(k=0;k<64;k++) { + x->tmatrix[i][j][k] = time * (k + 1); + } + } + } + } + return(void *)x; +} + + +void polyquant_setup(void) { + polyquant_class = class_new(gensym("polyquant"), + (t_newmethod)polyquant_new, + 0, sizeof(t_polyquant), + 0, A_DEFFLOAT, A_DEFFLOAT, 0); + post("|---------->polyquant<----------|"); + post("|---->polyrhythmic quantize<----|"); + post("|-->edward<--->kelly<--->2010<--|"); + + class_addbang(polyquant_class, polyquant_bang); + class_addfloat(polyquant_class, polyquant_float); + class_addmethod(polyquant_class, (t_method)polyquant_bpm, gensym("bpm"), A_DEFFLOAT, 0); + class_addmethod(polyquant_class, (t_method)polyquant_plimit, gensym("plimit"), A_DEFFLOAT, 0); + class_addmethod(polyquant_class, (t_method)polyquant_dlimit, gensym("dlimit"), A_DEFFLOAT, 0); + class_addmethod(polyquant_class, (t_method)polyquant_mode, gensym("mode"), A_DEFFLOAT, 0); + class_addmethod(polyquant_class, (t_method)polyquant_win, gensym("win"), A_DEFFLOAT, 0); +} -- cgit v1.2.1