~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kmid/player/midistat.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
 
 
3
    midistat.cc - class MidiStatus, change it internally and then send it. 
 
4
    Copyright (C) 1997,98,99  Antonio Larrosa Jimenez
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along with this program; if not, write to the Free Software
 
18
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 
 
20
    Send comments and bug fixes to antlarr@arrakis.es
 
21
    or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain
 
22
 
 
23
***************************************************************************/
 
24
#include "midistat.h"
 
25
#include "deviceman.h"
 
26
#include "sndcard.h"
 
27
#include "../version.h"
 
28
 
 
29
extern int MT32toGM[128];
 
30
 
 
31
MidiStatus::MidiStatus()
 
32
{
 
33
    int i;
 
34
    tempo=1000000;
 
35
    for (int chn=0;chn<N_CHANNELS;chn++)
 
36
    {
 
37
        chn_patch[chn]=0;
 
38
        chn_bender[chn]=0x4000;
 
39
        chn_pressure[chn]=127;
 
40
        for (i=0;i<N_CTL;i++)
 
41
            chn_controller[chn][i]=0;
 
42
        chn_controller[chn][CTL_MAIN_VOLUME]=127;
 
43
        chn_controller[chn][11]=127;
 
44
        chn_controller[chn][0x4a]=127;
 
45
        chn_lastisvolumeev[chn]=1;
 
46
    }
 
47
    
 
48
    
 
49
}
 
50
 
 
51
MidiStatus::~MidiStatus()
 
52
{
 
53
}
 
54
 
 
55
//    void noteOn       ( uchar chn, uchar note, uchar vel );
 
56
//    void noteOff      ( uchar chn, uchar note, uchar vel );
 
57
 
 
58
void MidiStatus::chnPatchChange ( uchar chn, uchar patch )
 
59
{
 
60
    chn_patch[chn]=patch;
 
61
}
 
62
 
 
63
void MidiStatus::chnPressure    ( uchar chn, uchar vel )
 
64
{
 
65
    chn_pressure[chn]=vel;
 
66
}
 
67
 
 
68
void MidiStatus::chnPitchBender ( uchar chn, uchar lsb,  uchar msb )
 
69
{
 
70
    chn_bender[chn]=((int)msb<<8|lsb);
 
71
}
 
72
 
 
73
void MidiStatus::chnController  ( uchar chn, uchar ctl , uchar v )
 
74
{
 
75
    if (ctl==7) chn_lastisvolumeev[chn]=1;
 
76
    else if (ctl==11) chn_lastisvolumeev[chn]=0;
 
77
    
 
78
    chn_controller[chn][ctl]=v;
 
79
}
 
80
 
 
81
void MidiStatus::tmrSetTempo(int v)
 
82
{
 
83
    tempo=v;
 
84
}
 
85
 
 
86
void MidiStatus::sendData(DeviceManager *midi,int gm)
 
87
{
 
88
    for (int chn=0;chn<N_CHANNELS;chn++)
 
89
    {
 
90
#ifdef MIDISTATDEBUG
 
91
        printf("Restoring channel %d\n",chn);
 
92
#endif
 
93
        midi->chnPatchChange(chn,
 
94
                             (gm==1)?(chn_patch[chn]):(MT32toGM[chn_patch[chn]]));
 
95
        midi->chnPitchBender(chn,chn_bender[chn]&0xFF,chn_bender[chn]>>8);
 
96
        midi->chnPressure(chn,chn_pressure[chn]);
 
97
        if (chn_lastisvolumeev[chn])
 
98
        {
 
99
            midi->chnController(chn,11,chn_controller[chn][11]);
 
100
            midi->chnController(chn,CTL_MAIN_VOLUME,chn_controller[chn][CTL_MAIN_VOLUME]);
 
101
        } else {
 
102
            midi->chnController(chn,CTL_MAIN_VOLUME,chn_controller[chn][CTL_MAIN_VOLUME]);
 
103
            midi->chnController(chn,11,chn_controller[chn][11]);
 
104
        }
 
105
        /*
 
106
         for (int i=0;i<N_CTL;i++)
 
107
         midi->chnController(chn,i,chn_controller[chn][i]);
 
108
         */
 
109
    }
 
110
    midi->tmrSetTempo(tempo);
 
111
    midi->sync();
 
112
}