<commit_before>//
// implicitmap.c
// a maxmsp and puredata external encapsulating the functionality of libmapper
// for performing implicit mapping 
// http://www.idmil.org/software/libmapper
// <NAME>, IDMIL 2010
//
// This software was written in the Input Devices and Music Interaction
// Laboratory at McGill University in Montreal, and is copyright those
// found in the AUTHORS file.  It is licensed under the GNU Lesser Public
// General License version 2.1 or later.  Please see COPYING for details.
// 

#ifndef PD
#define MAXMSP
#endif

// *********************************************************
// -(Includes)----------------------------------------------

#ifdef MAXMSP
    #include "ext.h"            // standard Max include, always required
    #include "ext_obex.h"       // required for new style Max object
    #include "ext_dictionary.h"
    #include "jpatcher_api.h"
#else
    #include "m_pd.h"
#endif
#include "mapper/mapper.h"
#include "mapper/mapper_db.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <lo/lo.h>

#include <unistd.h>
#include <arpa/inet.h>

#define INTERVAL 1
#define MAX_LIST 256

// *********************************************************
// -(object struct)-----------------------------------------
typedef struct _signal_ref
{
    void *x;
    int offset;
} t_signal_ref;

typedef struct _mapper 
{
    t_object ob;
    void *outlet1;
    void *outlet2;
    void *outlet3;
    void *clock;          // pointer to clock object
    void *timeout;
    char name[128];
    mapper_admin admin;
    mapper_device device;
    mapper_monitor monitor;
    lo_address address;
    mapper_db db;
    int ready;
    int new_in;
    t_atom buffer_in[MAX_LIST];
    int size_in;
    t_atom buffer_out[MAX_LIST];
    int size_out;
    int query_count;
    t_atom buffer[MAX_LIST];
    t_signal_ref signals_in[MAX_LIST];
    t_signal_ref signals_out[MAX_LIST];
} t_mapper;

static t_symbol *ps_list;
static int port = 9000;

// *********************************************************
// -(function prototypes)-----------------------------------
static void *mapper_new(t_symbol *s, int argc, t_atom *argv);
static void mapper_free(t_mapper *x);
static void mapper_list(t_mapper *x, t_symbol *s, int argc, t_atom *argv);
static void mapper_poll(t_mapper *x);
static void mapper_snapshot_timeout(t_mapper *x);
static void mapper_randomize(t_mapper *x);
static void mapper_input_handler(mapper_signal msig, mapper_db_signal props, mapper_timetag_t *time, void *value);
static void mapper_query_handler(mapper_signal msig, mapper_db_signal props, mapper_timetag_t *time, void *value);
static void mapper_connect_handler(mapper_db_connection con, mapper_db_action_t a, void *user);
static void mapper_print_properties(t_mapper *x);
static int mapper_setup_mapper(t_mapper *x);
static void mapper_snapshot(t_mapper *x);   
#ifdef MAXMSP
    void mapper_assist(t_mapper *x, void *b, long m, long a, char *s);
#endif
static void add_input(t_mapper *x);
static void add_output(t_mapper *x);
static int mapper_pack_signal_value(mapper_signal sig, t_atom *buffer, int max_length);
static int mapper_find_ordinal(const char *str);
static void mapper_update_input_vector_positions(t_mapper *x);
static void mapper_update_output_vector_positions(t_mapper *x);
static void set_sym(t_atom *argv, char *sym);
static void set_int(t_atom *argv, int i);
static int osc_prefix_cmp(const char *str1, const char *str2, const char **rest);

// *********************************************************
// -(global class pointer variable)-------------------------
static void *mapper_class;

// *********************************************************
// -(main)--------------------------------------------------
#ifdef MAXMSP
int main(void)
    {    
        t_class *c;
        c = class_new("implicitmap", (method)mapper_new, (method)mapper_free, 
                      (long)sizeof(t_mapper), 0L, A_GIMME, 0);
        class_addmethod(c, (method)mapper_assist,           "assist",   A_CANT,     0);
        class_addmethod(c, (method)mapper_snapshot,         "snapshot", A_GIMME,    0);
        class_addmethod(c, (method)mapper_randomize,        "randomize",A_GIMME,    0);
        class_addmethod(c, (method)mapper_list,             "list",     A_GIMME,    0);
        class_addmethod(c, (method)mapper_print_properties, "print",    A_GIMME,    0);
        class_register(CLASS_BOX, c); /* CLASS_NOBOX */
        mapper_class = c;
        ps_list = gensym("list");
        return 0;
    }
#else
    int mapper_setup(void)
    {
        t_class *c;
        c = class_new(gensym("mapper"), (t_newmethod)mapper_new, (t_method)mapper_free, 
                      (long)sizeof(t_mapper), 0L, A_GIMME, 0);        
        class_addmethod(c,   (t_method)mapper_snapshot,         gensym("snapshot"),  A_GIMME, 0);
        class_addmethod(c,   (t_method)mapper_randomize,        gensym("randomize"), A_GIMME, 0);
        class_addmethod(c,   (t_method)mapper_list,             gensym("list"),      A_GIMME, 0);
        class_addmethod(c,   (t_method)mapper_print_properties, gensym("print"),     A_GIMME, 0);
        mapper_class = c;
        ps_list = gensym("list");
        return 0;
    }
#endif

// *********************************************************
// -(new)---------------------------------------------------
void *mapper_new(t_symbol *s, int argc, t_atom *argv)
{
    t_mapper *x = NULL;
    long i;
    char alias[128];
    
    strncpy(alias, "implicitmap", 128);
    
#ifdef MAXMSP
    if (x = object_alloc(mapper_class)) {
        x->outlet3 = listout((t_object *)x);
        x->outlet2 = listout((t_object *)x);
        x->outlet1 = listout((t_object *)x);<commit_msg>Correct name of the class for PureData.<commit_after>//
// implicitmap.c
// a maxmsp and puredata external encapsulating the functionality of libmapper
// for performing implicit mapping 
// http://www.idmil.org/software/libmapper
// <NAME>, IDMIL 2010
//
// This software was written in the Input Devices and Music Interaction
// Laboratory at McGill University in Montreal, and is copyright those
// found in the AUTHORS file.  It is licensed under the GNU Lesser Public
// General License version 2.1 or later.  Please see COPYING for details.
// 

#ifndef PD
#define MAXMSP
#endif

// *********************************************************
// -(Includes)----------------------------------------------

#ifdef MAXMSP
    #include "ext.h"            // standard Max include, always required
    #include "ext_obex.h"       // required for new style Max object
    #include "ext_dictionary.h"
    #include "jpatcher_api.h"
#else
    #include "m_pd.h"
#endif
#include "mapper/mapper.h"
#include "mapper/mapper_db.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <lo/lo.h>

#include <unistd.h>
#include <arpa/inet.h>

#define INTERVAL 1
#define MAX_LIST 256

// *********************************************************
// -(object struct)-----------------------------------------
typedef struct _signal_ref
{
    void *x;
    int offset;
} t_signal_ref;

typedef struct _mapper 
{
    t_object ob;
    void *outlet1;
    void *outlet2;
    void *outlet3;
    void *clock;          // pointer to clock object
    void *timeout;
    char name[128];
    mapper_admin admin;
    mapper_device device;
    mapper_monitor monitor;
    lo_address address;
    mapper_db db;
    int ready;
    int new_in;
    t_atom buffer_in[MAX_LIST];
    int size_in;
    t_atom buffer_out[MAX_LIST];
    int size_out;
    int query_count;
    t_atom buffer[MAX_LIST];
    t_signal_ref signals_in[MAX_LIST];
    t_signal_ref signals_out[MAX_LIST];
} t_mapper;

static t_symbol *ps_list;
static int port = 9000;

// *********************************************************
// -(function prototypes)-----------------------------------
static void *mapper_new(t_symbol *s, int argc, t_atom *argv);
static void mapper_free(t_mapper *x);
static void mapper_list(t_mapper *x, t_symbol *s, int argc, t_atom *argv);
static void mapper_poll(t_mapper *x);
static void mapper_snapshot_timeout(t_mapper *x);
static void mapper_randomize(t_mapper *x);
static void mapper_input_handler(mapper_signal msig, mapper_db_signal props, mapper_timetag_t *time, void *value);
static void mapper_query_handler(mapper_signal msig, mapper_db_signal props, mapper_timetag_t *time, void *value);
static void mapper_connect_handler(mapper_db_connection con, mapper_db_action_t a, void *user);
static void mapper_print_properties(t_mapper *x);
static int mapper_setup_mapper(t_mapper *x);
static void mapper_snapshot(t_mapper *x);   
#ifdef MAXMSP
    void mapper_assist(t_mapper *x, void *b, long m, long a, char *s);
#endif
static void add_input(t_mapper *x);
static void add_output(t_mapper *x);
static int mapper_pack_signal_value(mapper_signal sig, t_atom *buffer, int max_length);
static int mapper_find_ordinal(const char *str);
static void mapper_update_input_vector_positions(t_mapper *x);
static void mapper_update_output_vector_positions(t_mapper *x);
static void set_sym(t_atom *argv, char *sym);
static void set_int(t_atom *argv, int i);
static int osc_prefix_cmp(const char *str1, const char *str2, const char **rest);

// *********************************************************
// -(global class pointer variable)-------------------------
static void *mapper_class;

// *********************************************************
// -(main)--------------------------------------------------
#ifdef MAXMSP
int main(void)
    {    
        t_class *c;
        c = class_new("implicitmap", (method)mapper_new, (method)mapper_free, 
                      (long)sizeof(t_mapper), 0L, A_GIMME, 0);
        class_addmethod(c, (method)mapper_assist,           "assist",   A_CANT,     0);
        class_addmethod(c, (method)mapper_snapshot,         "snapshot", A_GIMME,    0);
        class_addmethod(c, (method)mapper_randomize,        "randomize",A_GIMME,    0);
        class_addmethod(c, (method)mapper_list,             "list",     A_GIMME,    0);
        class_addmethod(c, (method)mapper_print_properties, "print",    A_GIMME,    0);
        class_register(CLASS_BOX, c); /* CLASS_NOBOX */
        mapper_class = c;
        ps_list = gensym("list");
        return 0;
    }
#else
    int implicitmap_setup(void)
    {
        t_class *c;
        c = class_new(gensym("implicitmap"), (t_newmethod)mapper_new, (t_method)mapper_free, 
                      (long)sizeof(t_mapper), 0L, A_GIMME, 0);        
        class_addmethod(c,   (t_method)mapper_snapshot,         gensym("snapshot"),  A_GIMME, 0);
        class_addmethod(c,   (t_method)mapper_randomize,        gensym("randomize"), A_GIMME, 0);
        class_addmethod(c,   (t_method)mapper_list,             gensym("list"),      A_GIMME, 0);
        class_addmethod(c,   (t_method)mapper_print_properties, gensym("print"),     A_GIMME, 0);
        mapper_class = c;
        ps_list = gensym("list");
        return 0;
    }
#endif

// *********************************************************
// -(new)---------------------------------------------------
void *mapper_new(t_symbol *s, int argc, t_atom *argv)
{
    t_mapper *x = NULL;
    long i;
    char alias[128];
    
    strncpy(alias, "implicitmap", 128);
    
#ifdef MAXMSP
    if (x = object_alloc(mapper_class)) {
        x->outlet3 = listout((t_object *)x);
        x->outlet2 = listout((t_object *)x);
        x->outlet1 = listout((t_object *)x);
{'fraction_non_alphanumeric': 0.20439923491566683, 'fraction_numerical': 0.007998608937576073, 'mean_word_length': 3.0389747191011236, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1144667', 'n_tokens_mistral': 3863, 'n_tokens_neox': 3728, 'n_words': 921}