2 Epichord - a midi sequencer
3 Copyright (C) 2008 Evan Rinehart
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to
18 The Free Software Foundation, Inc.
19 51 Franklin Street, Fifth Floor
20 Boston, MA 02110-1301, USA
26 #define MIDI_NOTE_OFF 0x80
27 #define MIDI_NOTE_ON 0x90
28 #define MIDI_AFTERTOUCH 0xA0
29 #define MIDI_CONTROLLER_CHANGE 0xB0
30 #define MIDI_PROGRAM_CHANGE 0xC0
31 #define MIDI_CHANNEL_PRESSURE 0xD0
32 #define MIDI_PITCH_WHEEL 0xE0
34 #define MAX_TRACK_NAME 256
45 int dur
; //for note on events
47 //struct mevent* off; //for note on events
48 //int off_index; //used when reloading
64 mevent(int ztype
, int ztick
, int zv1
){
85 selected
= e
->selected
;
92 struct mevent
* events
;
96 unsigned char r1
,g1
,b1
;//main color
97 unsigned char r2
,g2
,b2
;//bottom color
98 unsigned char r3
,g3
,b3
;//top color
99 unsigned char rx
,gx
,bx
;//xray color
101 float h
, s
, v
; //color
106 events
= new mevent();//dummy
141 // unsigned char color[3][3];
145 int scrollx
, scrolly
;
157 seqpat(int ztrack
, int ztick
, int zdur
, pattern
* zp
){
180 scrollx
= zs
->scrollx
;
181 scrolly
= zs
->scrolly
;
183 selected
= zs
->selected
;
184 modified
= zs
->modified
;
187 seqpat(seqpat
* zs
, pattern
* zp
){
198 scrollx
= zs
->scrollx
;
199 scrolly
= zs
->scrolly
;
201 selected
= zs
->selected
;
202 modified
= zs
->modified
;
219 char name
[MAX_TRACK_NAME
];
239 head
= new seqpat(0,0,0,new pattern());
261 void tswap(T
* old
, T
* nu
){
262 nu
->next
= old
->next
;
263 nu
->prev
= old
->prev
;
266 old
->prev
->next
= nu
; //'atomic'
269 old
->next
->prev
= nu
; //prev ptrs are only read by gui thread
274 void tremove(T
* old
){
276 old
->prev
->next
= old
->next
; //'atomic'
279 old
->next
->prev
= old
->prev
; //prev ptrs are only read by gui thread
284 void tinsert(T
* targ
, T
* nu
){
286 nu
->next
= targ
->next
;
288 targ
->next
= nu
; //'atomic'
290 nu
->next
->prev
= nu
; //prev ptrs are only read by gui thread
295 T
* tfind(T
* begin
, int tick
){
298 if(ptr
->next
->tick
> tick
){
306 mevent
* find_off(mevent
* e
);
313 virtual void undo() {}
314 virtual void redo() {}
318 void set_undo(Command
* c
);
319 void push_undo(int n
);
323 int clear_undos(int number
);
327 class CreateSeqpat
: public Command
{
334 CreateSeqpat(int track
, int tick
, seqpat
* zs
, int copy
);
337 if(s
->p
->ref_c
-- == 0){
347 class CreateSeqpatBlank
: public CreateSeqpat
{
351 CreateSeqpatBlank(int track
, int tick
, int len
);
356 class DeleteSeqpat
: public Command
{
361 DeleteSeqpat(seqpat
* zs
){
369 class ResizeSeqpat
: public Command
{
375 ResizeSeqpat(seqpat
* zs
, int dur
){
388 class MoveSeqpat
: public Command
{
390 seqpat
*targ1
, *targ2
;
396 MoveSeqpat(seqpat
* zs
, int track
, int tick
);
402 class SplitSeqpat
: public Command
{
409 SplitSeqpat(seqpat
* zs
){
417 if(p2
->ref_c
-- == 0){
429 class CreateNote
: public Command
{
436 CreateNote(pattern
* zp
, int note
, int vel
, int tick
, int dur
){
438 e1
= new mevent(MIDI_NOTE_ON
, tick
, note
);
441 e2
= new mevent(MIDI_NOTE_OFF
, tick
+dur
, note
);
442 //e->off = new mevent(MIDI_NOTE_OFF, tick+dur, note);
454 class CreateNoteOn
: public Command
{
460 CreateNoteOn(pattern
* zp
, int note
, int vel
, int tick
, int dur
){
462 e1
= new mevent(MIDI_NOTE_ON
, tick
, note
);
474 class CreateNoteOff
: public Command
{
484 CreateNoteOff(pattern
* zp
, int note
, int vel
, int tick
);
493 class DeleteNote
: public Command
{
500 DeleteNote(pattern
* zp
, mevent
* ze
){
510 class MoveNote
: public Command
{
523 MoveNote(pattern
* zp
, mevent
* ze
, int zt
, int znote
){
538 class ResizeNote
: public Command
{
547 ResizeNote(pattern
* zp
, mevent
* ze
, int dur
){
554 r2
->prev
= tfind
<mevent
>(p
->events
, ze
->tick
+ dur
);
555 r2
->tick
= ze
->tick
+ dur
;
569 class CreateEvent
: public Command
{
575 CreateEvent(pattern
* zp
, int type
, int tick
, int value1
, int value2
){
577 e
= new mevent(type
,tick
,value1
);
579 e
->prev
= tfind
<mevent
>(zp
->events
,tick
);
580 e
->next
= e
->prev
->next
;
590 class DeleteEvent
: public Command
{
595 DeleteEvent(mevent
* ze
){
603 class ChangeEvent
: public Command
{
609 ChangeEvent(mevent
* ze
, int zv1
, int zv2
){
624 int play_seq(int cur_tick
, void (*dispatch_event
)(mevent
*, int port
, int tick
));
625 int set_seq_pos(int new_tick
);
627 void set_rec_track(int t
);
630 int set_default_hsv_value(float v
);
632 void set_undo(Command
* c
);
633 void undo_push(int n
);
640 //encodes data in e as a midi event placed in buf
641 int midi_encode(mevent
* e
, int chan
, unsigned char* buf
, size_t* n
);
643 //decodes midi data and creates a new mevent
644 int midi_decode(char* buf
, mevent
* e
);