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
38 unsigned char bytes
[16];
45 void set(int note
, int value
);
63 int dur
; //for note on events
65 //struct mevent* off; //for note on events
66 //int off_index; //used when reloading
84 mevent(int ztype
, int ztick
, int zv1
){
106 selected
= e
->selected
;
107 modified
= e
->modified
;
114 struct mevent
* events
;
115 struct pattern
* next
;
118 unsigned char r1
,g1
,b1
;//main color
119 unsigned char r2
,g2
,b2
;//bottom color
120 unsigned char r3
,g3
,b3
;//top color
121 unsigned char rx
,gx
,bx
;//xray color
123 float h
, s
, v
; //color
130 void append(mevent
* ze
);
131 void insert(mevent
* ze
, int tick
);
147 void push(pattern
* p
);
150 void insert(pattern
* p
, int n
);
156 layerstack(pattern
* p
);
172 // unsigned char color[3][3];
175 int record_flag
;//0=on record, erase/save. 1=dont
177 int scrollx
, scrolly
;
186 void record_check(int mode
);
204 seqpat(int ztrack
, int ztick
, int zdur
, pattern
* zp
){
233 scrollx
= zs
->scrollx
;
234 scrolly
= zs
->scrolly
;
236 selected
= zs
->selected
;
237 modified
= zs
->modified
;
243 seqpat(seqpat
* zs
, pattern
* zp
){
255 scrollx
= zs
->scrollx
;
256 scrolly
= zs
->scrolly
;
258 selected
= zs
->selected
;
259 modified
= zs
->modified
;
274 if(layers
->ref_c
== 0){
320 name
= (char*)malloc(8);
323 head
= new seqpat(0,0,0,new pattern());
352 void tswap(T
* old
, T
* nu
){
353 nu
->next
= old
->next
;
354 nu
->prev
= old
->prev
;
357 old
->prev
->next
= nu
; //'atomic'
360 old
->next
->prev
= nu
; //prev ptrs are only read by gui thread
365 void tremove(T
* old
){
367 old
->prev
->next
= old
->next
; //'atomic'
370 old
->next
->prev
= old
->prev
; //prev ptrs are only read by gui thread
375 void tinsert(T
* targ
, T
* nu
){
377 nu
->next
= targ
->next
;
379 targ
->next
= nu
; //'atomic'
381 nu
->next
->prev
= nu
; //prev ptrs are only read by gui thread
386 T
* tfind(T
* begin
, int tick
){
389 if(ptr
->next
->tick
> tick
){
397 mevent
* find_off(mevent
* e
);
404 virtual void undo() {}
405 virtual void redo() {}
409 void set_undo(Command
* c
);
410 void push_undo(int n
);
414 int clear_undos(int number
);
418 class CreateSeqpat
: public Command
{
425 CreateSeqpat(int track
, int tick
, seqpat
* zs
, int copy
);
428 if(s
->p
->ref_c
-- == 0){
438 class CreateSeqpatBlank
: public CreateSeqpat
{
442 CreateSeqpatBlank(int track
, int tick
, int len
);
447 class DeleteSeqpat
: public Command
{
452 DeleteSeqpat(seqpat
* zs
){
460 class ResizeSeqpat
: public Command
{
466 ResizeSeqpat(seqpat
* zs
, int dur
){
479 class MoveSeqpat
: public Command
{
481 seqpat
*targ1
, *targ2
;
487 MoveSeqpat(seqpat
* zs
, int track
, int tick
);
495 class SplitSeqpat
: public Command
{
502 SplitSeqpat(seqpat
* zs
, int tick
);
514 class JoinSeqpat
: public Command
{
521 JoinSeqpat(seqpat
* zs1
, seqpat
* zs2
);
531 class ClearSeqpat
: public Command
{
539 ClearSeqpat(seqpat
* zs
){
554 class LayerSeqpat
: public Command
{
561 LayerSeqpat(seqpat
* zs
){
578 class CreateNote
: public Command
{
585 CreateNote(pattern
* zp
, int note
, int vel
, int tick
, int dur
){
587 e1
= new mevent(MIDI_NOTE_ON
, tick
, note
);
590 e2
= new mevent(MIDI_NOTE_OFF
, tick
+dur
, note
);
592 //e->off = new mevent(MIDI_NOTE_OFF, tick+dur, note);
604 class CreateNoteOn
: public Command
{
610 CreateNoteOn(pattern
* zp
, int note
, int vel
, int tick
, int dur
){
612 e1
= new mevent(MIDI_NOTE_ON
, tick
, note
);
624 class CreateNoteOff
: public Command
{
634 CreateNoteOff(pattern
* zp
, int note
, int vel
, int tick
);
643 class DeleteNote
: public Command
{
650 DeleteNote(pattern
* zp
, mevent
* ze
){
660 class MoveNote
: public Command
{
673 MoveNote(pattern
* zp
, mevent
* ze
, int zt
, int znote
){
688 class ResizeNote
: public Command
{
699 ResizeNote(pattern
* zp
, mevent
* ze
, int dur
);
713 class CreateEvent
: public Command
{
719 CreateEvent(pattern
* zp
, int type
, int tick
, int value1
, int value2
){
721 e
= new mevent(type
,tick
,value1
);
723 e
->prev
= tfind
<mevent
>(zp
->events
,tick
);
724 e
->next
= e
->prev
->next
;
734 class DeleteEvent
: public Command
{
739 DeleteEvent(mevent
* ze
){
747 class ChangeEvent
: public Command
{
753 ChangeEvent(mevent
* ze
, int zv1
, int zv2
){
766 int play_seq(int cur_tick
);
767 int set_seq_pos(int new_tick
);
769 void set_rec_track(int t
);
772 void tracks_auto_off();
774 int set_default_hsv_value(float v
);
776 void set_undo(Command
* c
);
777 void undo_push(int n
);
783 void reset_record_flags();
786 //encodes data in e as a midi event placed in buf
787 int midi_encode(mevent
* e
, int chan
, unsigned char* buf
, size_t* n
);
789 //decodes midi data and creates a new mevent
790 int midi_decode(char* buf
, mevent
* e
);