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(pattern
* p
);
131 void insert(pattern
* p
, int n
);
137 layerstack(pattern
* p
);
153 // unsigned char color[3][3];
156 int record_flag
;//0=on record, erase/save. 1=dont
158 int scrollx
, scrolly
;
167 void record_check(int mode
);
185 seqpat(int ztrack
, int ztick
, int zdur
, pattern
* zp
){
214 scrollx
= zs
->scrollx
;
215 scrolly
= zs
->scrolly
;
217 selected
= zs
->selected
;
218 modified
= zs
->modified
;
224 seqpat(seqpat
* zs
, pattern
* zp
){
236 scrollx
= zs
->scrollx
;
237 scrolly
= zs
->scrolly
;
239 selected
= zs
->selected
;
240 modified
= zs
->modified
;
255 if(layers
->ref_c
== 0){
295 name
= (char*)malloc(8);
298 head
= new seqpat(0,0,0,new pattern());
321 void tswap(T
* old
, T
* nu
){
322 nu
->next
= old
->next
;
323 nu
->prev
= old
->prev
;
326 old
->prev
->next
= nu
; //'atomic'
329 old
->next
->prev
= nu
; //prev ptrs are only read by gui thread
334 void tremove(T
* old
){
336 old
->prev
->next
= old
->next
; //'atomic'
339 old
->next
->prev
= old
->prev
; //prev ptrs are only read by gui thread
344 void tinsert(T
* targ
, T
* nu
){
346 nu
->next
= targ
->next
;
348 targ
->next
= nu
; //'atomic'
350 nu
->next
->prev
= nu
; //prev ptrs are only read by gui thread
355 T
* tfind(T
* begin
, int tick
){
358 if(ptr
->next
->tick
> tick
){
366 mevent
* find_off(mevent
* e
);
373 virtual void undo() {}
374 virtual void redo() {}
378 void set_undo(Command
* c
);
379 void push_undo(int n
);
383 int clear_undos(int number
);
387 class CreateSeqpat
: public Command
{
394 CreateSeqpat(int track
, int tick
, seqpat
* zs
, int copy
);
397 if(s
->p
->ref_c
-- == 0){
407 class CreateSeqpatBlank
: public CreateSeqpat
{
411 CreateSeqpatBlank(int track
, int tick
, int len
);
416 class DeleteSeqpat
: public Command
{
421 DeleteSeqpat(seqpat
* zs
){
429 class ResizeSeqpat
: public Command
{
435 ResizeSeqpat(seqpat
* zs
, int dur
){
448 class MoveSeqpat
: public Command
{
450 seqpat
*targ1
, *targ2
;
456 MoveSeqpat(seqpat
* zs
, int track
, int tick
);
464 class SplitSeqpat
: public Command
{
471 SplitSeqpat(seqpat
* zs
, int tick
);
483 class JoinSeqpat
: public Command
{
490 JoinSeqpat(seqpat
* zs1
, seqpat
* zs2
);
500 class ClearSeqpat
: public Command
{
508 ClearSeqpat(seqpat
* zs
){
523 class LayerSeqpat
: public Command
{
530 LayerSeqpat(seqpat
* zs
){
547 class CreateNote
: public Command
{
554 CreateNote(pattern
* zp
, int note
, int vel
, int tick
, int dur
){
556 e1
= new mevent(MIDI_NOTE_ON
, tick
, note
);
559 e2
= new mevent(MIDI_NOTE_OFF
, tick
+dur
, note
);
561 //e->off = new mevent(MIDI_NOTE_OFF, tick+dur, note);
573 class CreateNoteOn
: public Command
{
579 CreateNoteOn(pattern
* zp
, int note
, int vel
, int tick
, int dur
){
581 e1
= new mevent(MIDI_NOTE_ON
, tick
, note
);
593 class CreateNoteOff
: public Command
{
603 CreateNoteOff(pattern
* zp
, int note
, int vel
, int tick
);
612 class DeleteNote
: public Command
{
619 DeleteNote(pattern
* zp
, mevent
* ze
){
629 class MoveNote
: public Command
{
642 MoveNote(pattern
* zp
, mevent
* ze
, int zt
, int znote
){
657 class ResizeNote
: public Command
{
668 ResizeNote(pattern
* zp
, mevent
* ze
, int dur
);
682 class CreateEvent
: public Command
{
688 CreateEvent(pattern
* zp
, int type
, int tick
, int value1
, int value2
){
690 e
= new mevent(type
,tick
,value1
);
692 e
->prev
= tfind
<mevent
>(zp
->events
,tick
);
693 e
->next
= e
->prev
->next
;
703 class DeleteEvent
: public Command
{
708 DeleteEvent(mevent
* ze
){
716 class ChangeEvent
: public Command
{
722 ChangeEvent(mevent
* ze
, int zv1
, int zv2
){
735 int play_seq(int cur_tick
);
736 int set_seq_pos(int new_tick
);
738 void set_rec_track(int t
);
741 int set_default_hsv_value(float v
);
743 void set_undo(Command
* c
);
744 void undo_push(int n
);
750 void reset_record_flags();
753 //encodes data in e as a midi event placed in buf
754 int midi_encode(mevent
* e
, int chan
, unsigned char* buf
, size_t* n
);
756 //decodes midi data and creates a new mevent
757 int midi_decode(char* buf
, mevent
* e
);