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
44 int dur
; //for note on events
46 //struct mevent* off; //for note on events
47 //int off_index; //used when reloading
65 mevent(int ztype
, int ztick
, int zv1
){
87 selected
= e
->selected
;
88 modified
= e
->modified
;
95 struct mevent
* events
;
99 unsigned char r1
,g1
,b1
;//main color
100 unsigned char r2
,g2
,b2
;//bottom color
101 unsigned char r3
,g3
,b3
;//top color
102 unsigned char rx
,gx
,bx
;//xray color
104 float h
, s
, v
; //color
111 void append(mevent
* ze
);
112 void insert(mevent
* ze
, int tick
);
128 void push_new(pattern
* p
);
134 layerstack(pattern
* p
);
150 // unsigned char color[3][3];
153 int record_flag
;//0=on record, erase/save. 1=dont
157 int scrollx
, scrolly
;
166 void record_check(int mode
);
186 seqpat(int ztrack
, int ztick
, int zdur
, pattern
* zp
){
217 scrollx
= zs
->scrollx
;
218 scrolly
= zs
->scrolly
;
220 selected
= zs
->selected
;
221 modified
= zs
->modified
;
229 seqpat(seqpat
* zs
, pattern
* zp
){
241 scrollx
= zs
->scrollx
;
242 scrolly
= zs
->scrolly
;
244 selected
= zs
->selected
;
245 modified
= zs
->modified
;
262 if(layers
->ref_c
== 0){
302 name
= (char*)malloc(8);
305 head
= new seqpat(0,0,0,new pattern());
328 void tswap(T
* old
, T
* nu
){
329 nu
->next
= old
->next
;
330 nu
->prev
= old
->prev
;
333 old
->prev
->next
= nu
; //'atomic'
336 old
->next
->prev
= nu
; //prev ptrs are only read by gui thread
341 void tremove(T
* old
){
343 old
->prev
->next
= old
->next
; //'atomic'
346 old
->next
->prev
= old
->prev
; //prev ptrs are only read by gui thread
351 void tinsert(T
* targ
, T
* nu
){
353 nu
->next
= targ
->next
;
355 targ
->next
= nu
; //'atomic'
357 nu
->next
->prev
= nu
; //prev ptrs are only read by gui thread
362 T
* tfind(T
* begin
, int tick
){
365 if(ptr
->next
->tick
> tick
){
373 mevent
* find_off(mevent
* e
);
380 virtual void undo() {}
381 virtual void redo() {}
385 void set_undo(Command
* c
);
386 void push_undo(int n
);
390 int clear_undos(int number
);
394 class CreateSeqpat
: public Command
{
401 CreateSeqpat(int track
, int tick
, seqpat
* zs
, int copy
);
404 if(s
->p
->ref_c
-- == 0){
414 class CreateSeqpatBlank
: public CreateSeqpat
{
418 CreateSeqpatBlank(int track
, int tick
, int len
);
423 class DeleteSeqpat
: public Command
{
428 DeleteSeqpat(seqpat
* zs
){
436 class ResizeSeqpat
: public Command
{
442 ResizeSeqpat(seqpat
* zs
, int dur
){
455 class MoveSeqpat
: public Command
{
457 seqpat
*targ1
, *targ2
;
463 MoveSeqpat(seqpat
* zs
, int track
, int tick
);
469 class SplitSeqpat
: public Command
{
476 SplitSeqpat(seqpat
* zs
){
484 if(--(p2
->ref_c
) == 0){
496 class CreateNote
: public Command
{
503 CreateNote(pattern
* zp
, int note
, int vel
, int tick
, int dur
){
505 e1
= new mevent(MIDI_NOTE_ON
, tick
, note
);
508 e2
= new mevent(MIDI_NOTE_OFF
, tick
+dur
, note
);
510 //e->off = new mevent(MIDI_NOTE_OFF, tick+dur, note);
522 class CreateNoteOn
: public Command
{
528 CreateNoteOn(pattern
* zp
, int note
, int vel
, int tick
, int dur
){
530 e1
= new mevent(MIDI_NOTE_ON
, tick
, note
);
542 class CreateNoteOff
: public Command
{
552 CreateNoteOff(pattern
* zp
, int note
, int vel
, int tick
);
561 class DeleteNote
: public Command
{
568 DeleteNote(pattern
* zp
, mevent
* ze
){
578 class MoveNote
: public Command
{
591 MoveNote(pattern
* zp
, mevent
* ze
, int zt
, int znote
){
606 class ResizeNote
: public Command
{
615 ResizeNote(pattern
* zp
, mevent
* ze
, int dur
);
628 class CreateEvent
: public Command
{
634 CreateEvent(pattern
* zp
, int type
, int tick
, int value1
, int value2
){
636 e
= new mevent(type
,tick
,value1
);
638 e
->prev
= tfind
<mevent
>(zp
->events
,tick
);
639 e
->next
= e
->prev
->next
;
649 class DeleteEvent
: public Command
{
654 DeleteEvent(mevent
* ze
){
662 class ChangeEvent
: public Command
{
668 ChangeEvent(mevent
* ze
, int zv1
, int zv2
){
681 int play_seq(int cur_tick
, void (*dispatch_event
)(mevent
*, int port
, int tick
));
682 int set_seq_pos(int new_tick
);
684 void set_rec_track(int t
);
687 int set_default_hsv_value(float v
);
689 void set_undo(Command
* c
);
690 void undo_push(int n
);
695 void reset_record_flags();
698 //encodes data in e as a midi event placed in buf
699 int midi_encode(mevent
* e
, int chan
, unsigned char* buf
, size_t* n
);
701 //decodes midi data and creates a new mevent
702 int midi_decode(char* buf
, mevent
* e
);