lmms
Cross-platform music production software
Loading...
Searching...
No Matches
allegro.h
Go to the documentation of this file.
1
46
47
48#ifndef ALLEGRO_H
49#define ALLEGRO_H
50#include <cassert>
51#include <cstdint>
52#include <cstring>
53#include <iostream>
54
55#define ALG_EPS 0.000001
56#define ALG_DEFAULT_BPM 100.0
57
59bool within(double d1, double d2, double epsilon);
60
61char *heapify(const char *s);
62
68typedef const char *Alg_attribute;
69#define alg_attr_name(a) ((a) + 1)
70#define alg_attr_type(a) (*(a))
71
74class Alg_atoms {
75public:
77 maxlen = len = 0;
78 atoms = nullptr;
79 }
80
87 virtual ~Alg_atoms() {
88 for (int i = 0; i < len; i++) {
89 delete atoms[i];
90 }
91 delete[] atoms;
92 }
93
96 Alg_attribute insert_string(const char *name);
97private:
98 long maxlen;
99 long len;
101
103 Alg_attribute insert_new(const char *name, char attr_type);
104 void expand(); // make more space
105};
106
107#ifdef _WIN32
108#define DLLEXPORT __declspec(dllexport)
109#else
110#define DLLEXPORT
111#endif
112
114
115
121public:
123 union {
124 double r;
125 const char *s;
126 int32_t i;
127 bool l;
128 const char *a;
129 };
130
135 Alg_parameter() { attr = "i"; }
137 void copy(Alg_parameter *);
138 char attr_type() { return alg_attr_type(attr); }
139 const char *attr_name() { return alg_attr_name(attr); }
140 void set_attr(Alg_attribute a) { attr = a; }
141 void show();
142};
143
144
147public:
150
152 next = list;
153 }
154
155 //~Alg_parameters() { }
156
166 static void insert_real(Alg_parameters **list, const char *name, double r);
168 static void insert_string(Alg_parameters **list, const char *name,
169 const char *s);
170 static void insert_integer(Alg_parameters **list, const char *name, int32_t i);
171 static void insert_logical(Alg_parameters **list, const char *name, bool l);
172 static void insert_atom(Alg_parameters **list, const char *name,
173 const char *s);
174 static Alg_parameters *remove_key(Alg_parameters **list, const char *name);
177};
178
179
180// these are type codes associated with certain attributes
181// see Alg_track::find() where these are bit positions in event_type_mask
182#define ALG_NOTE 0
183#define ALG_GATE 1
184#define ALG_BEND 2
185#define ALG_CONTROL 3
186#define ALG_PROGRAM 4
187#define ALG_PRESSURE 5
188#define ALG_KEYSIG 6
189#define ALG_TIMESIG_NUM 7
190#define ALG_TIMESIG_DEN 8
191#define ALG_OTHER 9
192
194// NOTE: there is no Alg_event() constructor because Alg_event is an
195// abstract class.
197protected:
199 char type;
200 long key;
201 static const char* description;
202public:
203 double time;
204 long chan;
205 virtual void show() = 0;
206
208 bool is_note() { return (type == 'n'); }
209
211 bool is_update() { return (type == 'u'); }
212
214 char get_type() { return type; }
215
220 int get_type_code();
221
222 bool get_selected() { return selected; }
223 void set_selected(bool b) { selected = b; }
224
225 // Note: notes are identified by a (channel, identifier) pair.
226 // For midi, the identifier is the key number (pitch). The identifier
227 // does not have to represent pitch; it's main purpose is to identify
228 // notes so that they can be named by subsequent update events.
229 long get_identifier() { return key; }
230 void set_identifier(long i) { key = i; }
237 void set_parameter(Alg_parameter *new_parameter);
238 void set_string_value(const char *attr, const char *value);
239 void set_real_value(const char *attr, double value);
240 void set_logical_value(const char *attr, bool value);
241 void set_integer_value(const char *attr, int32_t value);
242 void set_atom_value(const char *attr, const char *atom);
243
244 // Some note methods. These fail (via assert()) if this is not a note:
245 //
246 float get_pitch();
247 float get_loud();
248 // times are in seconds or beats, depending upon the units_are_seconds
249 // flag in the containing sequence
250 double get_start_time();
251 double get_end_time();
252 double get_duration();
253 void set_pitch(float);
254 void set_loud(float);
255 void set_duration(double);
256
263 bool has_attribute(const char *attr);
264
270 char get_attribute_type(const char *attr);
271
273 const char *get_string_value(const char *attr, const char *value = nullptr);
274
276 double get_real_value(const char *attr, double value = 0.0);
277
279 bool get_logical_value(const char *attr, bool value = false);
280
282 long get_integer_value(const char *attr, int32_t value = 0);
283
285 const char *get_atom_value(const char *attr, const char *value = nullptr);
286
290 void delete_attribute(const char *attr);
291
296 const char *get_attribute();
297
303 char get_update_type();
304
309 const char *get_string_value();
310
311 double get_real_value();
312 bool get_logical_value();
313 int32_t get_integer_value();
314
319 const char *get_atom_value();
320
323 bool overlap(double t, double len, bool all);
324
329 const char *GetDescription();
330
331 Alg_event() { selected = false; }
332 virtual ~Alg_event() = default;
333};
334
335
336class Alg_note : public Alg_event {
337public:
338 ~Alg_note() override;
339 Alg_note(Alg_note *note);
340 float pitch;
341 float loud;
342 double dur;
344 Alg_note() { type = 'n'; parameters = nullptr; }
345 void show() override;
346};
347
348
349class Alg_update : public Alg_event {
350public:
351 ~Alg_update() override = default;
352 Alg_update(Alg_update *update);
354
355
356 Alg_update() { type = 'u'; }
357 void show() override;
358};
359
360
363private:
364 long maxlen;
365 void expand();
366protected:
367 long len;
369public:
379 bool in_use;
380 virtual int length() { return len; }
382 assert(i >= 0 && i < len);
383 return events[i];
384 }
386 maxlen = len = 0;
387 events = nullptr;
388 last_note_off = 0;
389 in_use = false;
390 }
391
393 virtual ~Alg_events();
394 void set_events(Alg_event **e, long l, long m) {
395 delete[] events;
396 events = e; len = l; maxlen = m;
397 }
398
399 void insert(Alg_event *event);
400 void append(Alg_event *event);
401 Alg_event *uninsert(long index);
402};
403
404class Alg_track;
405
407protected:
408 char type;
409 static const char *last_error_message;
410
414
415 static int sequences;
416
425
431 double beat_dur;
432 double real_dur;
433public:
442 virtual Alg_event *&operator[](int i);
444 beat_dur = 0.0; real_dur = 0.0; events_owner = nullptr; type = 'e'; }
446
447 char get_type() { return type; }
449
452 // note that the events contained in the list are not destroyed
453 ~Alg_event_list() override = default;
454
456 double get_beat_dur() { return beat_dur; }
457 void set_beat_dur(double d) { beat_dur = d; }
458 double get_real_dur() { return real_dur; }
459 void set_real_dur(double d) { real_dur = d; }
460
469 virtual void set_start_time(Alg_event *event, double);
481};
482
483
485class Alg_beat {
486public:
487 Alg_beat(double t, double b) {
488 time = t; beat = b; }
489 Alg_beat() = default;
490 double time;
491 double beat;
492};
493
494
497private:
498 long maxlen;
499 void expand();
500public:
501 long len;
504 assert(i >= 0 && i < len);
505 return beats[i];
506 }
508 maxlen = len = 0;
509 beats = nullptr;
510 expand();
511 beats[0].time = 0;
512 beats[0].beat = 0;
513 len = 1;
514 }
515 ~Alg_beats() { delete[] beats; }
516 void insert(long i, Alg_beat *beat);
517};
518
519
521private:
523public:
531 last_tempo_flag = true;
532 refcount = 0;
533 }
535 long length() { return beats.len; }
536 void show();
537 long locate_time(double time);
538 long locate_beat(double beat);
539 double beat_to_time(double beat);
540 double time_to_beat(double time);
547 void insert_beat(double time, double beat);
548 bool insert_tempo(double tempo, double beat);
550 double get_tempo(double beat);
552 bool set_tempo(double tempo, double start_beat, double end_beat);
553 bool stretch_region(double b0, double b1, double dur);
554 void cut(double start, double len, bool units_are_seconds);
555 void trim(double start, double end, bool units_are_seconds);
556 void paste(double start, Alg_track *tr);
559 void insert_time(double start, double len);
562 void insert_beats(double start, double len);
563 void dereference() {
564 --refcount;
565 if (refcount <= 0) {
566 delete this;
567 }
568 }
569 void reference() {
570 refcount++;
571 }
572};
573
574
578 protected:
579 char *buffer;
580 char *ptr;
581 long len;
582 public:
584 buffer = nullptr;
585 ptr = nullptr;
586 len = 0;
587 }
588 virtual ~Serial_buffer() = default;
589
590 long get_posn() { return static_cast<long>(ptr - buffer); }
591 long get_len() { return len; }
592};
593
594
596public:
601 ~Serial_read_buffer() override = default;
602 void get_pad() {
603 while (reinterpret_cast<uintptr_t>(ptr) & 7) { ptr++; }
604 }
605
608 void init_for_read(void *buf, long n) {
609 buffer = static_cast<char *>(buf);
610 ptr = static_cast<char *>(buf);
611 len = n;
612 }
613 char get_char() { return *ptr++; }
614 void unget_chars(int n) { ptr -= n; } // undo n get_char() calls
615 int32_t get_int32() {
616 const int32_t i = *(reinterpret_cast<int32_t *>(ptr));
617 ptr += sizeof(int32_t);
618 return i;
619 }
620 float get_float() {
621 const float f = *(reinterpret_cast<float *>(ptr));
622 ptr += sizeof(float);
623 return f;
624 }
625 double get_double() {
626 const double d = *(reinterpret_cast<double *>(ptr));
627 ptr += sizeof(double);
628 return d;
629 }
630 const char *get_string() {
631 char *s = ptr;
632 [[maybe_unused]] char *fence = buffer + len;
633 assert(ptr < fence);
634 while (*ptr++) { assert(ptr < fence); }
635 get_pad();
636 return s;
637 }
638 void check_input_buffer(long needed) {
639 assert(get_posn() + needed <= len);
640 }
641};
642
643
645 public:
651 ~Serial_write_buffer() override { delete[] buffer; }
654 void store_int32(long offset, int32_t value) {
655 assert(offset <= static_cast<long>(get_posn() - sizeof(int32_t)));
656 *reinterpret_cast<int32_t *>(buffer + offset) = value;
657 }
658 [[deprecated("Use store_int32() instead")]]
659 void store_long(long offset, long value) { store_int32(offset, static_cast<int32_t>(value)); }
660 void check_buffer(long needed);
661 void set_string(const char *s) {
662 [[maybe_unused]] char *fence = buffer + len;
663 assert(ptr < fence);
664 // two brackets surpress a g++ warning, because this is an
665 // assignment operator inside a test.
666 while ((*ptr++ = *s++)) { assert(ptr < fence); }
667 assert(reinterpret_cast<char *>(reinterpret_cast<uintptr_t>(ptr + 7) & ~7) <= fence);
668 pad();
669 }
670 void set_int32(int32_t v) {
671 *(reinterpret_cast<long *>(ptr)) = v;
672 ptr += sizeof(int32_t);
673 }
674 void set_double(double v) {
675 *(reinterpret_cast<double *>(ptr)) = v;
676 ptr += sizeof(double);
677 }
678 void set_float(float v) {
679 *(reinterpret_cast<float *>(ptr)) = v;
680 ptr += sizeof(float);
681 }
682 void set_char(char v) { *ptr++ = v; }
683 void pad() {
684 while (reinterpret_cast<uintptr_t>(ptr) & 7) { set_char(0); }
685 }
686 void *to_heap(long *len) {
687 *len = get_posn();
688 char *newbuf = new char[*len];
689 memcpy(newbuf, buffer, *len);
690 return newbuf;
691 }
692};
693
694class Alg_seq;
695
696class Alg_track : public Alg_event_list {
697protected:
700 char *get_string(char **p, long *b);
701 long get_int32(char **p, long *b);
702 double get_double(char **p, long *b);
703 float get_float(char **p, long *b);
709 void unserialize_parameter(Alg_parameter *parm_ptr);
710public:
711 void serialize_track();
712 void unserialize_track();
713 Alg_event *&operator[](int i) override {
714 assert(i >= 0 && i < len);
715 return events[i];
716 }
717 Alg_track() { units_are_seconds = false; time_map = nullptr;
718 set_time_map(nullptr); type = 't'; }
719
720 Alg_track(Alg_time_map *map, bool seconds);
721
723
724 Alg_track(Alg_track &track);
726 Alg_track(Alg_event_list &event_list, Alg_time_map *map,
727 bool units_are_seconds);
728 ~Alg_track() override {
729 if (time_map) {
731 }
732 time_map = nullptr;
733 }
734
739 virtual void serialize(void **buffer, long *bytes);
740
743 static Alg_track *unserialize(void *buffer, long len);
744
748 return (get_type() == 's' ? (Alg_seq*) this : nullptr); }
749
753 virtual void convert_to_beats();
754 virtual void convert_to_seconds();
755 void set_dur(double dur);
756 double get_dur() { return (units_are_seconds ? real_dur : beat_dur); }
757
767 virtual void set_time_map(Alg_time_map *map);
769
773 Alg_note *create_note(double time, int channel, int identifier,
774 float pitch, float loudness, double duration);
777 Alg_update *create_update(double time, int channel, int identifier);
782 virtual void add(Alg_event *event) { insert(event); }
783
784 //
785 // Editing regions
786 //
787
802 virtual Alg_track *cut(double t, double len, bool all);
803
811 virtual Alg_track *copy(double t, double len, bool all);
812
823 void paste(double t, Alg_event_list *seq); // Shifts notes
824
835 virtual void merge(double t, Alg_event_list *seq);
836
844 virtual void clear(double t, double len, bool all);
845
850 virtual void silence(double t, double len, bool all);
851
857 virtual void insert_silence(double t, double len);
858
859 //
860 // Accessing for screen display
861 //
862
869 virtual Alg_event_list *find(double t, double len, bool all,
870 long channel_mask, long event_type_mask);
871
872 virtual void set_in_use(bool flag) { in_use = flag; }
873 //
874 // MIDI playback
875 //
876 // See Alg_iterator
877};
878
879
885public:
886 double beat;
887 double num;
888 double den;
889 Alg_time_sig(double b, double n, double d) {
890 beat = b; num = n; den = d;
891 }
893 beat = 0; num = 0; den = 0;
894 }
895 void beat_to_measure(double beat, double *measure, double *m_beat,
896 double *num, double *den);
897
898};
899
900
913private:
914 long maxlen;
915 void expand();
916 long len;
918public:
920 maxlen = len = 0;
921 time_sigs = nullptr;
922 }
924 assert(i >= 0 && i < len);
925 return time_sigs[i];
926 }
927 ~Alg_time_sigs() { delete[] time_sigs; }
928 void show();
929 long length() { return len; }
930 int find_beat(double beat);
932 double get_bar_len(double beat);
933 void insert(double beat, double num, double den, bool force = false);
934 void cut(double start, double end, double dur);
935 void trim(double start, double end);
936 void paste(double start, Alg_seq *seq);
937 void insert_beats(double beat, double len);
939 double nearest_beat(double beat);
940};
941
942
945private:
946 long maxlen;
947 void expand();
948 void expand_to(int new_max);
949 long len;
950public:
953 assert(i >= 0 && i < len);
954 return *tracks[i];
955 }
956 long length() { return len; }
958 maxlen = len = 0;
959 tracks = nullptr;
960 }
961 ~Alg_tracks();
963 void append(Alg_track *track);
964 void add_track(int track_num, Alg_time_map *time_map, bool seconds);
965 void reset();
966 void set_in_use(bool flag);
967};
968
969
982
983
985 void *cookie;
987 long index;
988 bool note_on;
989 double offset;
990 double time;
991};
992
993
995private:
996 long maxlen;
997 void expand();
998 void expand_to(int new_max);
999 long len;
1004 long index;
1005 void *cookie;
1006 double offset;
1007 void show();
1008 bool earlier(int i, int j);
1009 void insert(Alg_events *events, long index, bool note_on,
1010 void *cookie, double offset);
1012 bool remove_next(Alg_events *&events, long &index, bool &note_on,
1013 void *&cookie, double &offset, double &time);
1014public:
1019 long length() { return len; }
1020 Alg_iterator(Alg_seq *s, bool note_off) {
1021 seq = s;
1022 note_off_flag = note_off;
1023 maxlen = len = 0;
1024 pending_events = nullptr;
1025 }
1026
1034 void begin_seq(Alg_seq *s, void *cookie = nullptr, double offset = 0.0);
1035
1039 void begin(void *cookie = nullptr) { begin_seq(seq, cookie); }
1049 Alg_event *next(bool *note_on = nullptr, void **cookie_ptr = nullptr,
1050 double *offset_ptr = nullptr, double end_time = 0);
1056 void request_note_off();
1057 void end();
1058};
1059
1060
1065class Alg_seq : public Alg_track {
1066protected:
1068 void serialize_seq();
1071 Alg_event *write_track_name(std::ostream &file, int n,
1073public:
1080 units_are_seconds = true; type = 's';
1082 add_track(0); // default is one empty track
1083 }
1086 }
1087
1091 void seq_from_track(Alg_track &tr);
1093 Alg_seq(std::istream &file, bool smf, double *offset_ptr = nullptr);
1095 Alg_seq(const char *filename, bool smf, double *offset_ptr = nullptr);
1096 ~Alg_seq() override;
1097 int get_read_error() { return error; }
1098 void serialize(void **buffer, long *bytes) override;
1099 void copy_time_sigs_to(Alg_seq *dest);
1100 void set_time_map(Alg_time_map *map) override;
1101
1105 void unserialize_seq();
1106
1108 void write(std::ostream &file, bool in_secs, double offset = 0.0);
1110 bool write(const char *filename, double offset = 0.0);
1111 void smf_write(std::ostream &file);
1112 bool smf_write(const char *filename);
1113
1115 int tracks();
1116
1118 void add_track(int track_num) {
1120 }
1121
1124 Alg_track *track(int);
1125
1126 Alg_event *&operator[](int i) override;
1127
1128 void convert_to_seconds() override;
1129 void convert_to_beats() override;
1130
1131 Alg_track *cut_from_track(int track_num, double start, double dur,
1132 bool all);
1133 Alg_seq *cut(double t, double len, bool all) override;
1134 void insert_silence_in_track(int track_num, double t, double len);
1135 void insert_silence(double t, double len) override;
1136 Alg_track *copy_track(int track_num, double t, double len, bool all);
1137 Alg_seq *copy(double start, double len, bool all) override;
1138 void paste(double start, Alg_seq *seq);
1139 void clear(double t, double len, bool all) override;
1140 void merge(double t, Alg_event_list *seq) override;
1141 void silence(double t, double len, bool all) override;
1142 void clear_track(int track_num, double start, double len, bool all);
1143 void silence_track(int track_num, double start, double len, bool all);
1144 Alg_event_list *find_in_track(int track_num, double t, double len,
1145 bool all, long channel_mask,
1146 long event_type_mask);
1147
1149 long seek_time(double time, int track_num);
1150 bool insert_beat(double time, double beat);
1157 double nearest_beat_time(double time, double *beat);
1159 bool insert_tempo(double bpm, double beat);
1162 bool stretch_region(double b0, double b1, double dur);
1165 void add_event(Alg_event *event, int track_num);
1166 void add(Alg_event */*event*/) override { assert(false); }
1168 double get_tempo(double beat);
1169 bool set_tempo(double bpm, double start_beat, double end_beat);
1170
1172 double get_bar_len(double beat);
1173 void set_time_sig(double beat, double num, double den);
1174 void beat_to_measure(double beat, long *measure, double *m_beat,
1175 double *num, double *den);
1177 void merge_tracks();
1178 void set_in_use(bool flag) override;
1179};
1180
1181
1188#endif
#define ALG_DEFAULT_BPM
default tempo
Definition allegro.h:56
DLLEXPORT Alg_atoms symbol_table
Definition allegro.cpp:25
#define alg_attr_type(a)
Definition allegro.h:70
const char * Alg_attribute
Definition allegro.h:68
#define DLLEXPORT
Definition allegro.h:110
char * heapify(const char *s)
Put a string on the heap.
Definition allegro.cpp:36
bool within(double d1, double d2, double epsilon)
Checks if d1 and d2 within epsilon of each other.
Definition allegro.cpp:29
#define alg_attr_name(a)
Definition allegro.h:69
Alg_error
Definition allegro.h:970
@ alg_error_syntax
Definition allegro.h:980
@ alg_error_open
Definition allegro.h:972
@ alg_no_error
no error reading Allegro or MIDI file
Definition allegro.h:971
Symbol table of Alg_attribute objects and other unique strings.
Definition allegro.h:74
Alg_atoms()
Definition allegro.h:76
void expand()
Definition allegro.cpp:44
virtual ~Alg_atoms()
Definition allegro.h:87
Alg_attribute insert_string(const char *name)
insert/lookup attribute by name (without prefixed type)
Definition allegro.cpp:87
Alg_attribute insert_new(const char *name, char attr_type)
Insert an Attribute not in table after moving attr to heap.
Definition allegro.cpp:62
long len
Definition allegro.h:99
Alg_attribute insert_attribute(Alg_attribute attr)
insert/lookup an atttribute
Definition allegro.cpp:75
Alg_attribute * atoms
Definition allegro.h:100
long maxlen
Definition allegro.h:98
Used to contruct a tempo map.
Definition allegro.h:485
double beat
Definition allegro.h:491
double time
Definition allegro.h:490
Alg_beat(double t, double b)
Definition allegro.h:487
Alg_beat()=default
A list of Alg_beat objects used in Alg_seq.
Definition allegro.h:496
Alg_beats()
Definition allegro.h:507
~Alg_beats()
Definition allegro.h:515
void insert(long i, Alg_beat *beat)
Definition allegro.cpp:804
long len
Definition allegro.h:501
long maxlen
Definition allegro.h:498
Alg_beat & operator[](int i)
Definition allegro.h:503
Alg_beat * beats
Definition allegro.h:502
void expand()
Definition allegro.cpp:792
Definition allegro.h:406
static const char * last_error_message
Definition allegro.h:409
Alg_track * get_owner()
Definition allegro.h:448
int sequence_number
Definition allegro.h:424
Alg_event_list()
Definition allegro.h:443
virtual Alg_event *& operator[](int i)
Definition allegro.cpp:737
Alg_track * events_owner
Definition allegro.h:413
virtual void set_start_time(Alg_event *event, double)
Definition allegro.cpp:743
double get_beat_dur()
Returns the duration of the sequence in beats or seconds.
Definition allegro.h:456
static int sequences
to keep track of sequence numbers
Definition allegro.h:415
void set_beat_dur(double d)
Definition allegro.h:457
char type
'e' Alg_event_list, 't' Alg_track, 's' Alg_seq
Definition allegro.h:408
double beat_dur
Definition allegro.h:431
~Alg_event_list() override=default
double get_real_dur()
Definition allegro.h:458
void set_real_dur(double d)
Definition allegro.h:459
char get_type()
Definition allegro.h:447
const char * get_last_error_message()
get text description of run-time errors detected, clear error
Definition allegro.h:471
double real_dur
Definition allegro.h:432
Abstract superclass of Alg_note and Alg_update.
Definition allegro.h:196
double get_duration()
get duration in seconds or beats
Definition allegro.cpp:386
Alg_event()
Definition allegro.h:331
int get_type_code()
Definition allegro.cpp:229
bool has_attribute(const char *attr)
Test if note has attribute/value pair.
Definition allegro.cpp:417
void set_parameter(Alg_parameter *new_parameter)
Definition allegro.cpp:268
const char * get_atom_value()
Get the update's atom value.
Definition allegro.cpp:575
bool is_update()
Check whether an Alg_event is a parameter update.
Definition allegro.h:211
bool get_selected()
Definition allegro.h:222
void set_pitch(float)
Definition allegro.cpp:394
const char * GetDescription()
Computes a text description of this event.
void set_integer_value(const char *attr, int32_t value)
Definition allegro.cpp:328
float get_loud()
get loudness (MIDI velocity)
Definition allegro.cpp:362
char type
'e' event, 'n' note, 'u' update
Definition allegro.h:199
char get_attribute_type(const char *attr)
Get the associated attribute type.
Definition allegro.cpp:428
double get_start_time()
get start time in seconds or beats
Definition allegro.cpp:370
const char * get_string_value()
Get the update's string value.
Definition allegro.cpp:539
void set_logical_value(const char *attr, bool value)
Definition allegro.cpp:315
void set_atom_value(const char *attr, const char *atom)
Definition allegro.cpp:341
void set_real_value(const char *attr, double value)
Definition allegro.cpp:299
void delete_attribute(const char *attr)
Delete an attribute/value pair.
Definition allegro.cpp:514
long get_identifier()
get MIDI key or note identifier of note or update
Definition allegro.h:229
bool is_note()
Check whether an Alg_event is a note.
Definition allegro.h:208
void set_identifier(long i)
Definition allegro.h:230
double time
Definition allegro.h:203
float get_pitch()
get pitch in steps – use this even for MIDI
Definition allegro.cpp:354
bool get_logical_value()
get the update's logical value
Definition allegro.cpp:557
long key
note identifier
Definition allegro.h:200
void set_string_value(const char *attr, const char *value)
Definition allegro.cpp:286
bool selected
Definition allegro.h:198
long chan
Definition allegro.h:204
void set_duration(double)
Definition allegro.cpp:409
static const char * description
static buffer for debugging (in Alg_event)
Definition allegro.h:201
virtual ~Alg_event()=default
bool overlap(double t, double len, bool all)
Definition allegro.cpp:584
double get_real_value()
get the update's real value
Definition allegro.cpp:548
void set_selected(bool b)
Definition allegro.h:223
int32_t get_integer_value()
get the update's integer value
Definition allegro.cpp:566
const char * get_attribute()
get the update's attribute (string)
Definition allegro.cpp:522
double get_end_time()
get end time in seconds or beats
Definition allegro.cpp:378
virtual void show()=0
char get_update_type()
Get the update's type.
Definition allegro.cpp:531
char get_type()
Definition allegro.h:214
void set_loud(float)
Definition allegro.cpp:401
A sequence of Alg_event objects.
Definition allegro.h:362
long maxlen
Definition allegro.h:364
Alg_event *& operator[](int i)
Definition allegro.h:381
virtual int length()
Definition allegro.h:380
bool in_use
Definition allegro.h:379
void expand()
Definition allegro.cpp:657
void set_events(Alg_event **e, long l, long m)
Definition allegro.h:394
void insert(Alg_event *event)
for use by Alg_track and Alg_seq
Definition allegro.cpp:669
void append(Alg_event *event)
Definition allegro.cpp:706
Alg_events()
Definition allegro.h:385
Alg_event * uninsert(long index)
Definition allegro.cpp:693
Alg_event ** events
events is array of pointers
Definition allegro.h:368
double last_note_off
Definition allegro.h:376
long len
Definition allegro.h:367
Definition allegro.h:994
void show()
Definition allegro.cpp:2733
void begin_seq(Alg_seq *s, void *cookie=nullptr, double offset=0.0)
Definition allegro.cpp:3527
bool note_off_flag
Remembers if we are iterating over note-off events as well as note-on and update events.
Definition allegro.h:1018
Alg_iterator(Alg_seq *s, bool note_off)
Definition allegro.h:1020
void begin(void *cookie=nullptr)
Definition allegro.h:1039
Alg_pending_event * pending_events
Definition allegro.h:1001
long length()
Definition allegro.h:1019
long len
Definition allegro.h:999
Alg_seq * seq
Definition allegro.h:1000
long index
remembers index of current event
Definition allegro.h:1004
void insert(Alg_events *events, long index, bool note_on, void *cookie, double offset)
Definition allegro.cpp:2762
Alg_event * next(bool *note_on=nullptr, void **cookie_ptr=nullptr, double *offset_ptr=nullptr, double end_time=0)
Definition allegro.cpp:3540
void end()
clean up after enumerating events
Definition allegro.cpp:3586
~Alg_iterator()
Definition allegro.h:1015
bool remove_next(Alg_events *&events, long &index, bool &note_on, void *&cookie, double &offset, double &time)
returns the info on the next pending event in the priority queue
Definition allegro.cpp:2800
void request_note_off()
Definition allegro.cpp:3579
void expand()
Definition allegro.cpp:2719
Alg_events * events_ptr
the next four fields are mainly for request_note_off()
Definition allegro.h:1003
long maxlen
Definition allegro.h:996
void expand_to(int new_max)
Definition allegro.cpp:2707
bool earlier(int i, int j)
Definition allegro.cpp:2743
double offset
Definition allegro.h:1006
void * cookie
remembers the cookie associated with next event
Definition allegro.h:1005
Definition allegro.h:336
float pitch
pitch in semitones (69 = A440)
Definition allegro.h:340
void show() override
Definition allegro.cpp:626
Alg_note(Alg_note *note)
copy constructor
Definition allegro.cpp:602
Alg_parameters * parameters
attribute/value pair list
Definition allegro.h:343
Alg_note()
Definition allegro.h:344
double dur
duration in seconds (normally to release point)
Definition allegro.h:342
float loud
dynamic corresponding to MIDI velocity
Definition allegro.h:341
An attribute/value pair.
Definition allegro.h:120
Alg_attribute attr
Definition allegro.h:122
void show()
Definition allegro.cpp:110
Alg_parameter()
Definition allegro.h:135
void set_attr(Alg_attribute a)
Definition allegro.h:140
char attr_type()
Definition allegro.h:138
void copy(Alg_parameter *)
copy from another parameter
Definition allegro.cpp:100
const char * attr_name()
Definition allegro.h:139
A list of attribute/value pairs.
Definition allegro.h:146
static Alg_parameters * remove_key(Alg_parameters **list, const char *name)
Definition allegro.cpp:200
Alg_parameters(Alg_parameters *list)
Definition allegro.h:151
static void insert_atom(Alg_parameters **list, const char *name, const char *s)
Definition allegro.cpp:189
static void insert_logical(Alg_parameters **list, const char *name, bool l)
Definition allegro.cpp:178
Alg_parameter parm
Definition allegro.h:149
static void insert_real(Alg_parameters **list, const char *name, double r)
Definition allegro.cpp:145
static void insert_string(Alg_parameters **list, const char *name, const char *s)
insert string will copy string to heap
Definition allegro.cpp:156
static void insert_integer(Alg_parameters **list, const char *name, int32_t i)
Definition allegro.cpp:168
Alg_parameter * find(Alg_attribute attr)
find an attribute/value pair
Definition allegro.cpp:216
class Alg_parameters * next
Definition allegro.h:148
An array of Alg_events.
Definition allegro.h:1065
Alg_event_list * find_in_track(int track_num, double t, double len, bool all, long channel_mask, long event_type_mask)
Definition allegro.cpp:3298
void add(Alg_event *) override
Definition allegro.h:1166
void write(std::ostream &file, bool in_secs, double offset=0.0)
write an ascii representation to file
Definition allegrowr.cpp:83
double get_bar_len(double beat)
get the bar length in beats starting at beat
Definition allegro.cpp:3458
void set_time_map(Alg_time_map *map) override
Definition allegro.cpp:3011
void silence(double t, double len, bool all) override
Definition allegro.cpp:3246
void copy_time_sigs_to(Alg_seq *dest)
a utility function
Definition allegro.cpp:3001
void paste(double start, Alg_seq *seq)
Definition allegro.cpp:3182
void silence_track(int track_num, double start, double len, bool all)
Definition allegro.cpp:3238
void insert_silence(double t, double len) override
Definition allegro.cpp:3102
int tracks()
Returns the number of tracks.
Definition allegro.cpp:2917
Alg_track * cut_from_track(int track_num, double start, double dur, bool all)
Definition allegro.cpp:2992
Alg_seq(Alg_track *track)
Definition allegro.h:1090
int channel_offset_per_track
used to encode track_num into channel
Definition allegro.h:1074
void seq_from_track(Alg_track &tr)
Definition allegro.cpp:2873
void merge(double t, Alg_event_list *seq) override
Definition allegro.cpp:3224
void set_in_use(bool flag) override
set in_use flag on all tracks
Definition allegro.cpp:3615
void convert_to_beats() override
Change units.
Definition allegro.cpp:2954
void serialize(void **buffer, long *bytes) override
Definition allegro.cpp:1398
void beat_to_measure(double beat, long *measure, double *m_beat, double *num, double *den)
Definition allegro.cpp:3470
Alg_error error
Definition allegro.h:1069
int beat_x
Definition allegro.h:1077
void serialize_seq()
Definition allegro.cpp:1429
void add_event(Alg_event *event, int track_num)
Definition allegro.cpp:3416
void unserialize_seq()
Definition allegro.cpp:1592
Alg_tracks track_list
array of Alg_events
Definition allegro.h:1075
void clear(double t, double len, bool all) override
Definition allegro.cpp:3262
void insert_silence_in_track(int track_num, double t, double len)
Definition allegro.cpp:3095
void clear_track(int track_num, double start, double len, bool all)
Definition allegro.cpp:3254
Alg_time_sigs time_sig
Definition allegro.h:1076
Alg_seq()
Definition allegro.h:1084
long seek_time(double time, int track_num)
find index of first score event after time
Definition allegro.cpp:3321
Alg_seq * copy(double start, double len, bool all) override
Definition allegro.cpp:3132
void set_time_sig(double beat, double num, double den)
Definition allegro.cpp:3464
bool set_tempo(double bpm, double start_beat, double end_beat)
Definition allegro.cpp:3438
void add_track(int track_num)
create a track
Definition allegro.h:1118
bool insert_beat(double time, double beat)
Definition allegro.cpp:3335
void basic_initialization()
Definition allegro.h:1078
Alg_track * copy_track(int track_num, double t, double len, bool all)
Definition allegro.cpp:3126
bool insert_tempo(double bpm, double beat)
warning: insert_tempo may change representation from seconds to beats
Definition allegro.cpp:3380
Alg_seq(Alg_track &track)
Definition allegro.h:1089
Alg_event * write_track_name(std::ostream &file, int n, Alg_events &events)
an internal function used for writing Allegro track names
Definition allegrowr.cpp:51
void convert_to_seconds() override
Definition allegro.cpp:2969
Alg_seq * cut(double t, double len, bool all) override
Definition allegro.cpp:3020
Alg_track * track(int)
Definition allegro.cpp:2923
Alg_iterator * pending
iterator used internally by Alg_seq methods
Definition allegro.h:1067
bool stretch_region(double b0, double b1, double dur)
Definition allegro.cpp:3368
Alg_event *& operator[](int i) override
Definition allegro.cpp:2933
int get_read_error()
Definition allegro.h:1097
double get_tempo(double beat)
get the tempo starting at beat
Definition allegro.cpp:3432
void merge_tracks()
void set_events(Alg_event **events, long len, long max);
Definition allegro.cpp:3591
void smf_write(std::ostream &file)
Definition allegrosmfwr.cpp:653
double nearest_beat_time(double time, double *beat)
Definition allegro.cpp:3357
Definition allegro.h:520
long locate_time(double time)
Definition allegro.cpp:843
bool stretch_region(double b0, double b1, double dur)
Definition allegro.cpp:1049
Alg_time_map()
Definition allegro.h:527
long locate_beat(double beat)
Definition allegro.cpp:853
void trim(double start, double end, bool units_are_seconds)
Definition allegro.cpp:1079
bool last_tempo_flag
Definition allegro.h:526
double last_tempo
Definition allegro.h:525
Alg_beats beats
array of Alg_beat
Definition allegro.h:524
bool insert_tempo(double tempo, double beat)
Definition allegro.cpp:953
double beat_to_time(double beat)
Definition allegro.cpp:863
void insert_time(double start, double len)
Definition allegro.cpp:1236
double time_to_beat(double time)
Definition allegro.cpp:898
void insert_beats(double start, double len)
Definition allegro.cpp:1261
bool set_tempo(double tempo, double start_beat, double end_beat)
set the tempo over a region
Definition allegro.cpp:1026
void show()
Definition allegro.cpp:832
void reference()
Definition allegro.h:569
long length()
Definition allegro.h:535
void cut(double start, double len, bool units_are_seconds)
Definition allegro.cpp:1134
void insert_beat(double time, double beat)
add a point to the map
Definition allegro.cpp:926
int refcount
Definition allegro.h:522
void paste(double start, Alg_track *tr)
Definition allegro.cpp:1197
double get_tempo(double beat)
get the tempo starting at beat
Definition allegro.cpp:990
void dereference()
Definition allegro.h:563
Represents a single time signature.
Definition allegro.h:884
Alg_time_sig(double b, double n, double d)
Definition allegro.h:889
double beat
when does this take effect?
Definition allegro.h:886
Alg_time_sig()
Definition allegro.h:892
double num
what is the "numerator" (top number?)
Definition allegro.h:887
void beat_to_measure(double beat, double *measure, double *m_beat, double *num, double *den)
double den
what is the "denominator" (bottom number?)
Definition allegro.h:888
A dynamic array of Alg_time_sig objects.
Definition allegro.h:912
double nearest_beat(double beat)
find the nearest beat (see Alg_seq::nearest_beat) to beat
Definition allegro.cpp:2591
void trim(double start, double end)
retain just start to end
Definition allegro.cpp:2262
Alg_time_sig & operator[](int i)
Definition allegro.h:923
~Alg_time_sigs()
Definition allegro.h:927
long maxlen
Definition allegro.h:914
long len
Definition allegro.h:916
int find_beat(double beat)
Definition allegro.cpp:2114
void paste(double start, Alg_seq *seq)
Definition allegro.cpp:2383
double get_bar_len(double beat)
get the number of beats per measure starting at beat
Definition allegro.cpp:2125
void show()
Definition allegro.cpp:2104
void expand()
make more space
Definition allegro.cpp:2042
void insert(double beat, double num, double den, bool force=false)
Definition allegro.cpp:2055
long length()
Definition allegro.h:929
Alg_time_sig * time_sigs
Definition allegro.h:917
void insert_beats(double beat, double len)
Definition allegro.cpp:2525
void cut(double start, double end, double dur)
remove from start to end
Definition allegro.cpp:2137
Alg_time_sigs()
Definition allegro.h:919
Definition allegro.h:696
virtual Alg_event_list * find(double t, double len, bool all, long channel_mask, long event_type_mask)
Definition allegro.cpp:2012
bool units_are_seconds
Definition allegro.h:699
void serialize_parameter(Alg_parameter *parm)
Definition allegro.cpp:1522
double get_double(char **p, long *b)
static Serial_read_buffer ser_read_buf
Definition allegro.h:704
virtual void convert_to_beats()
Change units.
Definition allegro.cpp:1744
static Alg_track * unserialize(void *buffer, long len)
Definition allegro.cpp:1561
virtual void merge(double t, Alg_event_list *seq)
Definition allegro.cpp:1939
Alg_note * create_note(double time, int channel, int identifier, float pitch, float loudness, double duration)
Definition allegro.cpp:1797
virtual void insert_silence(double t, double len)
Definition allegro.cpp:2000
long get_int32(char **p, long *b)
virtual Alg_track * cut(double t, double len, bool all)
Definition allegro.cpp:1821
Alg_event * copy_event(Alg_event *event)
make a complete copy
Definition allegro.cpp:1290
virtual void set_time_map(Alg_time_map *map)
Definition allegro.cpp:1729
virtual void convert_to_seconds()
Definition allegro.cpp:1764
~Alg_track() override
Definition allegro.h:728
Alg_seq * to_alg_seq()
Definition allegro.h:747
virtual void add(Alg_event *event)
Definition allegro.h:782
virtual void silence(double t, double len, bool all)
Definition allegro.cpp:1979
Alg_event *& operator[](int i) override
Definition allegro.h:713
virtual void serialize(void **buffer, long *bytes)
Definition allegro.cpp:1328
Alg_update * create_update(double time, int channel, int identifier)
Definition allegro.cpp:1811
static Serial_write_buffer ser_write_buf
Definition allegro.h:705
void unserialize_parameter(Alg_parameter *parm_ptr)
Definition allegro.cpp:1694
void unserialize_track()
Definition allegro.cpp:1640
Alg_track()
Definition allegro.h:717
virtual void clear(double t, double len, bool all)
Definition allegro.cpp:1955
bool get_units_are_seconds()
Are we using beats or seconds?
Definition allegro.h:751
void set_dur(double dur)
Definition allegro.cpp:1784
float get_float(char **p, long *b)
void serialize_track()
Definition allegro.cpp:1470
virtual Alg_track * copy(double t, double len, bool all)
Definition allegro.cpp:1862
Alg_time_map * get_time_map()
Definition allegro.h:768
virtual void set_in_use(bool flag)
Definition allegro.h:872
void paste(double t, Alg_event_list *seq)
Definition allegro.cpp:1889
char * get_string(char **p, long *b)
Alg_time_map * time_map
Definition allegro.h:698
double get_dur()
Definition allegro.h:756
A sequence of Alg_events objects.
Definition allegro.h:944
void reset()
Definition allegro.cpp:2683
long len
Definition allegro.h:949
void expand_to(int new_max)
Definition allegro.cpp:2627
void append(Alg_track *track)
Append a track to tracks. This Alg_tracks becomes the owner of track.
Definition allegro.cpp:2646
void set_in_use(bool flag)
handy to set in_use flag on all tracks
Definition allegro.cpp:2699
long maxlen
Definition allegro.h:946
Alg_track & operator[](int i)
Definition allegro.h:952
long length()
Definition allegro.h:956
Alg_track ** tracks
tracks is array of pointers
Definition allegro.h:951
void add_track(int track_num, Alg_time_map *time_map, bool seconds)
Definition allegro.cpp:2656
void expand()
Definition allegro.cpp:2638
Alg_tracks()
Definition allegro.h:957
Definition allegro.h:349
~Alg_update() override=default
void show() override
Definition allegro.cpp:649
Alg_update()
Definition allegro.h:356
Alg_parameter parameter
an update contains one attr/value pair
Definition allegro.h:353
Alg_update(Alg_update *update)
copy constructor
Definition allegro.cpp:641
char * buffer
Definition allegro.h:579
long get_posn()
Definition allegro.h:590
long get_len()
Definition allegro.h:591
virtual ~Serial_buffer()=default
Serial_buffer()
Definition allegro.h:583
char * ptr
Definition allegro.h:580
long len
Definition allegro.h:581
Definition allegro.h:595
void init_for_read(void *buf, long n)
Definition allegro.h:608
~Serial_read_buffer() override=default
char get_char()
Definition allegro.h:613
double get_double()
Definition allegro.h:625
const char * get_string()
Definition allegro.h:630
int32_t get_int32()
Definition allegro.h:615
void get_pad()
Definition allegro.h:602
void unget_chars(int n)
Definition allegro.h:614
void check_input_buffer(long needed)
Definition allegro.h:638
float get_float()
Definition allegro.h:620
Definition allegro.h:644
void check_buffer(long needed)
Definition allegro.cpp:1407
void * to_heap(long *len)
Definition allegro.h:686
void pad()
Definition allegro.h:683
void set_int32(int32_t v)
Definition allegro.h:670
void init_for_write()
Definition allegro.h:652
void set_string(const char *s)
Definition allegro.h:661
void set_char(char v)
Definition allegro.h:682
void store_int32(long offset, int32_t value)
Writes an int32_t at a given offset.
Definition allegro.h:654
~Serial_write_buffer() override
Definition allegro.h:651
void set_double(double v)
Definition allegro.h:674
void set_float(float v)
Definition allegro.h:678
void store_long(long offset, long value)
Definition allegro.h:659
Definition allegro.h:984
void * cookie
client-provided sequence identifier
Definition allegro.h:985
bool note_on
is this a note-on or a note-off (if applicable)?
Definition allegro.h:988
double time
time for this event
Definition allegro.h:990
long index
offset of this event
Definition allegro.h:987
double offset
time offset for events
Definition allegro.h:989
Alg_events * events
the array of events
Definition allegro.h:986
const char * a
symbol (atom)