Subversion Repositories svn.mios

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
44 tk 1
// $Id: midi.c 44 2008-01-30 21:39:30Z tk $
2
/*
3
 * MIDI program module
4
 *
5
 * ==========================================================================
6
 *
7
 * Copyright (C) 2005  Thorsten Klose (tk@midibox.org)
8
 *
9
 * ==========================================================================
10
 *
11
 * This file is part of a MIOS application
12
 *
13
 * This application is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This application is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with This application; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 *
27
 * ==========================================================================
28
 */
29
 
30
/////////////////////////////////////////////////////////////////////////////
31
// Include files
32
/////////////////////////////////////////////////////////////////////////////
33
 
34
#include <cmios.h>
35
#include <pic18fregs.h>
36
 
37
#include "main.h"
38
#include "midi.h"
39
 
40
/////////////////////////////////////////////////////////////////////////////
41
// Global variables
42
/////////////////////////////////////////////////////////////////////////////
43
 
44
midi_note_t midi_note[16];
45
 
46
unsigned char midi_cc_chn0[128];
47
 
48
unsigned int midi_pitch_bender[16];
49
 
50
/////////////////////////////////////////////////////////////////////////////
51
// This function initializes the MIDI module
52
// it should be called from USER_Init() in main.c
53
/////////////////////////////////////////////////////////////////////////////
54
void MIDI_Init(void)
55
{
56
  unsigned char i;
57
 
58
  for(i=0; i<sizeof(midi_note); ++i) {
59
    midi_note[i].ALL = 0;
60
  }
61
 
62
  for(i=0; i<sizeof(midi_cc_chn0); ++i) {
63
    midi_cc_chn0[i] = 0;
64
  }
65
 
66
  for(i=0; i<sizeof(midi_pitch_bender); ++i) {
67
    midi_pitch_bender[i] = 0;
68
  }
69
}
70
 
71
 
72
/////////////////////////////////////////////////////////////////////////////
73
// This function is called from MPROC_NotifyReceivedEvnt to notify a
74
// new MIDI event
75
/////////////////////////////////////////////////////////////////////////////
76
void MIDI_Evnt(unsigned char evnt0, unsigned char evnt1, unsigned char evnt2)
77
{
78
  unsigned char midi_cmd = evnt0 & 0xf0;
79
  unsigned char midi_chn = evnt0 & 0x0f;
80
 
81
  switch( midi_cmd ) {
82
 
83
    case 0x80: // Note Off
84
      evnt2 = 0x00; // force velocity to zero
85
    case 0x90: // Note On
86
      midi_note[midi_chn].NOTE = evnt1;
87
      midi_note[midi_chn].GATE = evnt2 > 0 ? 1 : 0;
88
      break;
89
 
90
    case 0xa0: // aftertouch
91
      // nothing to do
92
      break;
93
 
94
    case 0xb0: // CC value
95
      // only storing CC values of channel #1
96
      if( midi_chn == 0x00 ) {
97
    midi_cc_chn0[evnt1] = evnt2;
98
      }
99
      break;
100
 
101
    case 0xc0: // Program Change
102
      // nothing to do
103
      break;
104
 
105
    case 0xd0: // Poly After Touch
106
      // nothing to do
107
      break;
108
 
109
    case 0xe0: // Pitch Bender
110
      midi_pitch_bender[midi_chn] = (evnt2 << 7) | evnt1;
111
      break;
112
 
113
  }
114
 
115
}
116