Skip to content

Commit

Permalink
deinit implemented and callback mechanism removed
Browse files Browse the repository at this point in the history
  • Loading branch information
vlazzarini committed Apr 2, 2024
1 parent f6a917c commit 21a6094
Show file tree
Hide file tree
Showing 24 changed files with 257 additions and 1,963 deletions.
2 changes: 1 addition & 1 deletion Engine/entry1.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ OENTRY opcodlst_1[] = {

/* IV - Sep 8 2002 - added entries for user defined opcodes, xin, xout */
/* and setksmps */
{ "##userOpcode", S(UOPCODE),0, 7, "", "", useropcdset, useropcd, useropcd, NULL },
{ "##userOpcode", S(UOPCODE),0, 7, "", "", useropcdset, useropcd, NULL, NULL },
/* IV - Sep 10 2002: removed perf time routines of xin and xout */
{ "xin", S(XIN_MAX),0, 1, "****************", "", xinset, NULL, NULL, NULL },
/* { "xin.64", S(XIN_HIGH),0, 1,
Expand Down
7 changes: 1 addition & 6 deletions Engine/insert.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,11 +932,6 @@ CSL */
static void deact(CSOUND *csound, INSDS *ip)
{ /* unlink single instr from activ chain */
INSDS *nxtp; /* and mark it inactive */
/* close any files in fd chain */

if (ip->nxtd != NULL)
csoundDeinitialiseOpcodes(csound, ip);

/* do deinit pass */
deinit_pass(csound, ip);
/* remove an active instrument */
Expand Down Expand Up @@ -2572,7 +2567,7 @@ static void instance(CSOUND *csound, int insno)
prvpds = prvpds->nxtp = opds; /* link into pchain */
opds->opadr = ep->kopadr; /* perf */
//if (UNLIKELY(odebug))
csound->Message(csound, "%s opadr = %p\n", ep->opname, (void*) opds->opadr);
csound->Message(csound, "%s opadr = %p\n", ep->opname,(void*) opds->opadr);
if (UNLIKELY(opds->opadr == NULL))
csoundDie(csound, Str("null opadr"));
}
Expand Down
1 change: 0 additions & 1 deletion Engine/symbtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ int add_udo_definition(CSOUND *csound, char *opname,
/* IV - Oct 31 2002: */
/* create a fake opcode so we can call it as such */
opc = find_opcode(csound, "##userOpcode");
opc->dopadr = NULL; // UDOs do not have a deinit, so we NULL it
memcpy(&tmpEntry, opc, sizeof(OENTRY));
tmpEntry.opname = cs_strdup(csound, opname);

Expand Down
12 changes: 0 additions & 12 deletions H/prototyp.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,6 @@ int insert_score_event_at_sample(CSOUND *, EVTBLK *, int64_t);

char *get_arg_string(CSOUND *, MYFLT);

/**
* Register a function to be called at note deactivation.
* Should be called from the initialisation routine of an opcode.
* 'p' is a pointer to the OPDS structure of the opcode, and 'func'
* is the function to be called, with the same arguments and return
* value as in the case of opcode init/perf functions.
* The functions are called in reverse order of registration.
* Returns zero on success.
*/
int csoundRegisterDeinitCallback(CSOUND *, void *p,
int (*func)(CSOUND *, void *));

/**
* Register a function to be called by csoundReset(), in reverse order
* of registration, before unloading external modules. The function takes
Expand Down
32 changes: 16 additions & 16 deletions Opcodes/OSC.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ static int32_t osc_send_set(CSOUND *csound, OSCSEND *p)
if (UNLIKELY(p->multicast)) lo_address_set_ttl(p->addr, 1);
p->cnt = 0;
p->last = 0;
csound->RegisterDeinitCallback(csound, p,
(int32_t (*)(CSOUND *, void *)) oscsend_deinit);
// csound->RegisterDeinitCallback(csound, p,
// (int32_t (*)(CSOUND *, void *)) oscsend_deinit);
p->thread = NULL;
return OK;
}
Expand Down Expand Up @@ -628,8 +628,8 @@ static int32_t osc_listener_init(CSOUND *csound, OSCINIT *p)
pp->nPorts = n + 1;
csound->Warning(csound, Str("OSC listener #%d started on port %s\n"), n, buff);
*(p->ihandle) = (MYFLT) n;
csound->RegisterDeinitCallback(csound, p,
(int32_t (*)(CSOUND *, void *)) OSC_deinit);
//csound->RegisterDeinitCallback(csound, p,
// (int32_t (*)(CSOUND *, void *)) OSC_deinit);
return OK;
}

Expand Down Expand Up @@ -666,8 +666,8 @@ static int32_t osc_listener_initMulti(CSOUND *csound, OSCINITM *p)
Str("OSC multicast listener #%d started on port %s\n"),
n, buff);
*(p->ihandle) = (MYFLT) n;
csound->RegisterDeinitCallback(csound, p,
(int32_t (*)(CSOUND *, void *)) OSC_deinit);
// csound->RegisterDeinitCallback(csound, p,
// (int32_t (*)(CSOUND *, void *)) OSC_deinit);
return OK;
}

Expand Down Expand Up @@ -789,8 +789,8 @@ static int32_t OSC_list_init(CSOUND *csound, OSCLISTEN *p)
p->c.method = lo_server_thread_add_method(p->port->thread,
p->c.saved_path, p->c.saved_types,
OSC_handler, p->port);
csound->RegisterDeinitCallback(csound, p,
(int32_t (*)(CSOUND *, void *)) OSC_listdeinit);
// csound->RegisterDeinitCallback(csound, p,
// (int32_t (*)(CSOUND *, void *)) OSC_listdeinit);
return OK;
}

Expand Down Expand Up @@ -1069,8 +1069,8 @@ static int32_t OSC_alist_init(CSOUND *csound, OSCLISTENA *p)
p->c.method = lo_server_thread_add_method(p->port->thread,
p->c.saved_path, p->c.saved_types,
OSC_ahandler, p->port);
csound->RegisterDeinitCallback(csound, p,
(int32_t (*)(CSOUND *, void *)) OSC_listadeinit);
// csound->RegisterDeinitCallback(csound, p,
// (int32_t (*)(CSOUND *, void *)) OSC_listadeinit);
return OK;
}

Expand Down Expand Up @@ -1116,17 +1116,17 @@ static int32_t OSC_alist(CSOUND *csound, OSCLISTENA *p)

static OENTRY localops[] = {
{ "OSCsend_lo", S(OSCSEND), 0, 3, "", "kSkSN",
(SUBR)osc_send_set, (SUBR)osc_send, NULL,NULL },
(SUBR)osc_send_set, (SUBR)osc_send, (SUBR) oscsend_deinit, NULL },
{ "OSCinit", S(OSCINIT), 0, 1, "i", "i",
(SUBR)osc_listener_init, NULL, NULL, NULL },
(SUBR)osc_listener_init, NULL, (SUBR) OSC_deinit , NULL },
{ "OSCinitM", S(OSCINITM), 0, 1, "i", "Si",
(SUBR)osc_listener_initMulti, NULL, NULL, NULL },
(SUBR)osc_listener_initMulti, NULL, (SUBR) OSC_deinit , NULL },
{ "OSClisten", S(OSCLISTEN),0, 3, "k", "iSSN",
(SUBR)OSC_list_init, (SUBR)OSC_list, NULL, NULL },
(SUBR)OSC_list_init, (SUBR)OSC_list, (SUBR) OSC_listdeinit, NULL },
{ "OSClisten", S(OSCLISTEN),0, 3, "k", "iSS",
(SUBR)OSC_list_init, (SUBR)OSC_list, NULL, NULL },
(SUBR)OSC_list_init, (SUBR)OSC_list, (SUBR) OSC_listdeinit, NULL },
{ "OSClisten", S(OSCLISTENA),0, 3, "kk[]", "iSS",
(SUBR)OSC_alist_init, (SUBR)OSC_alist, NULL, NULL },
(SUBR)OSC_alist_init, (SUBR)OSC_alist, (SUBR) OSC_listadeinit, NULL },
{ "OSCcount", S(OSCcount), 0, 3, "k", "",
(SUBR)OSCcounter, (SUBR)OSCcounter, NULL }
};
Expand Down
14 changes: 10 additions & 4 deletions Opcodes/OpcodeBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,20 @@ class OpcodeNoteoffBase
IGN(csound);
return NOTOK;
}

static int deinit_(CSOUND *csound, void *opcode)
{
if (!csound->GetReinitFlag(csound) && !csound->GetTieFlag(csound)) {
return noteoff_(csound, opcode);
}
return OK;
}

static int init_(CSOUND *csound, void *opcode)
{
if (!csound->GetReinitFlag(csound) && !csound->GetTieFlag(csound)) {
csound->RegisterDeinitCallback(csound, opcode,
&OpcodeNoteoffBase<T>::noteoff_);
}
return reinterpret_cast<T *>(opcode)->init(csound);
}

int kontrol(CSOUND *csound)
{
IGN(csound);
Expand Down
14 changes: 11 additions & 3 deletions Opcodes/cpumeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ typedef struct {
* cpus[0] thru cpus[n] == tics for each separate cpu
* cpus[Cpu_tot] == tics from the 1st /proc/stat line */

static int32_t deinit_cpupercent(CSOUND *csound, void *pdata)
int32_t deinit_cpupercent(CSOUND *csound, void *pdata)
{
CPUMETER *p = (CPUMETER *) pdata;
fclose(p->fp);
Expand Down Expand Up @@ -103,7 +103,7 @@ int32_t cpupercent_init(CSOUND *csound, CPUMETER* p)
p->cnt = (p->trig = (int32_t)(*p->itrig * csound->GetSr(csound)));
// Would it be better to add a deinit process so the closing happens in perf?
//csound->CreateFileHandle(csound, &p->fp, CSFILE_STD, "/proc/stat");
csound->RegisterDeinitCallback(csound, (void *) p, deinit_cpupercent);
// csound->RegisterDeinitCallback(csound, (void *) p, deinit_cpupercent);
return k;
}

Expand Down Expand Up @@ -224,6 +224,14 @@ typedef struct {
} CPUMETER;


int32_t deinit_cpupercent(CSOUND *csound, void *p)
{
IGN(p);
csound->Message(csound, "not implemented\n");
return OK;
}


int32_t cpupercent_init(CSOUND *csound, CPUMETER *p) {
IGN(p);
csound->Message(csound, "not implemented\n");
Expand Down Expand Up @@ -260,7 +268,7 @@ systime(CSOUND *csound, SYST *p){

static OENTRY cpumeter_localops[] = {
{ "cpumeter", S(CPUMETER), 0,3, "kzzzzzzzz", "i",
(SUBR)cpupercent_init, (SUBR)cpupercent },
(SUBR)cpupercent_init, (SUBR)cpupercent, (SUBR) deinit_cpupercent },
{ "systime", S(SYST),0, 3, "k", "", (SUBR)systime, (SUBR)systime},
{ "systime", S(SYST),0, 1, "i", "", (SUBR)systime}
};
Expand Down
6 changes: 3 additions & 3 deletions Opcodes/date.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static int32_t readf_init_(CSOUND *csound, READF *p, int32_t isstring)
}
if (UNLIKELY(p->fd==NULL))
return csound->InitError(csound, "%s", Str("readf: failed to open file"));
return csound->RegisterDeinitCallback(csound, p, readf_delete);
return OK; // csound->RegisterDeinitCallback(csound, p, readf_delete);
}

static int32_t readf_init(CSOUND *csound, READF *p){
Expand Down Expand Up @@ -238,9 +238,9 @@ static OENTRY date_localops[] =
{ "readfi", sizeof(READF), 0, 1, "Si", "i", (SUBR)readfi, },
{ "readfi.S", sizeof(READF), 0, 1, "Si", "S", (SUBR)readfi_S, },
{ "readf", sizeof(READF), 0, 3, "Sk", "i", (SUBR)readf_init,
(SUBR)readf },
(SUBR)readf, (SUBR)readf_delete },
{ "readf.S", sizeof(READF), 0, 3, "Sk", "S", (SUBR)readf_init_S,
(SUBR)readf }
(SUBR)readf, (SUBR)readf_delete }

};

Expand Down

0 comments on commit 21a6094

Please sign in to comment.