File: event.c

package info (click to toggle)
freebirth 0.3.2-9.2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 3,632 kB
  • ctags: 640
  • sloc: ansic: 4,724; makefile: 89; sh: 1
file content (122 lines) | stat: -rw-r--r-- 2,711 bytes parent folder | download | duplicates (4)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* Freebirth
 * Copyright (C) 1999 topher lafata <topher@topher.com>,
 *		      Jake Donham <jake@bitmechanic.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


#include "event.h"
#include <stdlib.h>
#include <string.h>

typedef struct trigger_event{
  int seq_handle;
  void(* fire)(event *this, sample_producer *target);
} trigger_event;


void fire_trigger(event *this, sample_producer *target) {
  target->trigger(target);
}

event *event_new_trigger(int seq_handle)
{
  trigger_event *out = (trigger_event *)malloc(sizeof(trigger_event));
  out->seq_handle = seq_handle;
  out->fire = fire_trigger;
  return (event *)out;
}




event_list *event_list_new()
{
  event_list *out = (event_list*)malloc(sizeof(event_list));
  out->events = (event**)malloc(sizeof(event*));
  out->length = 0;
  out->size = 1;
  
  return out;
}

void event_list_add(event_list *this,event *e)
{
  if (this->length == this->size)
    this->events = realloc(this->events,sizeof(event *) 
			   * ++this->size);
  
  
  this->events[this->length++] = e;
}


void event_list_remove(event_list *this,event *e)
{

  int i;
  for(i = 0; i < this->size;i++)
    if(e == this->events[i])
      memmove(this->events + i , this->events + i + 1,
	      (this->size - i - 1) * sizeof(event*));
  
  this->length--;

}

void event_list_delete(event_list *this)
{
  int i;
  for(i = 0; i < this->length;i++)
    free(this->events[i]);
  free(this->events);
  free(this);
}



event_bookeeper *e_bookeeper_new(int step, int seq_handle)
{
  event_bookeeper *out = (event_bookeeper *)malloc(sizeof(event_bookeeper));
  out->step = step;
  out->seq_handle = seq_handle;
  out->last_events = event_list_new();

  return out;
}


void clean_bookeeper(event_bookeeper *eb, seq* sequencer)
{
    event_list *el = eb->last_events;
    while(el->length != 0)
    {
      seq_delete_event(sequencer,eb->step,el->events[0]);
      free(el->events[0]);
      event_list_remove(el,el->events[0]);
    }  
}


/*
  Local Variables:
  mode: font-lock
  End:
*/