• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libtdemid
 

libtdemid

  • libtdemid
midistat.cpp
1 /**************************************************************************
2 
3  midistat.cpp - class MidiStatus, change it internally and then send it.
4  This file is part of LibKMid 0.9.5
5  Copyright (C) 1997,98,99,2000 Antonio Larrosa Jimenez
6  LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libtdemid.html
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 
23  Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
24 
25 ***************************************************************************/
26 #include "midistat.h"
27 #include "deviceman.h"
28 #include "sndcard.h"
29 
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 extern int MT32toGM[128];
35 
36 MidiStatus::MidiStatus()
37 {
38  int i;
39  tempo=1000000;
40  for (int chn=0;chn<16;chn++)
41  {
42  chn_patch[chn]=0;
43  chn_bender[chn]=0x4000;
44  chn_pressure[chn]=127;
45  for (i=0;i<256;i++)
46  chn_controller[chn][i]=0;
47  chn_controller[chn][CTL_MAIN_VOLUME]=127;
48  chn_controller[chn][11]=127;
49  chn_controller[chn][0x4a]=127;
50  chn_lastisvolumeev[chn]=1;
51  }
52 }
53 
54 MidiStatus::~MidiStatus()
55 {
56 }
57 
58 // void noteOn ( uchar chn, uchar note, uchar vel );
59 // void noteOff ( uchar chn, uchar note, uchar vel );
60 
61 void MidiStatus::chnPatchChange ( uchar chn, uchar patch )
62 {
63  chn_patch[chn]=patch;
64 }
65 
66 void MidiStatus::chnPressure ( uchar chn, uchar vel )
67 {
68  chn_pressure[chn]=vel;
69 }
70 
71 void MidiStatus::chnPitchBender ( uchar chn, uchar lsb, uchar msb )
72 {
73  chn_bender[chn]=((int)msb<<8|lsb);
74 }
75 
76 void MidiStatus::chnController ( uchar chn, uchar ctl , uchar v )
77 {
78  if (ctl==7) chn_lastisvolumeev[chn]=1;
79  else if (ctl==11) chn_lastisvolumeev[chn]=0;
80 
81  chn_controller[chn][ctl]=v;
82 }
83 
84 void MidiStatus::tmrSetTempo(int v)
85 {
86  tempo=v;
87 }
88 
89 void MidiStatus::sendData(DeviceManager *midi,int gm)
90 {
91  for (int chn=0;chn<16;chn++)
92  {
93 #ifdef MIDISTATDEBUG
94  printf("Restoring channel %d\n",chn);
95 #endif
96  midi->chnPatchChange(chn,
97  (gm==1)?(chn_patch[chn]):(MT32toGM[chn_patch[chn]]));
98  midi->chnPitchBender(chn,chn_bender[chn]&0xFF,chn_bender[chn]>>8);
99  midi->chnPressure(chn,chn_pressure[chn]);
100  if (chn_lastisvolumeev[chn])
101  {
102  midi->chnController(chn,11,chn_controller[chn][11]);
103  midi->chnController(chn,CTL_MAIN_VOLUME,chn_controller[chn][CTL_MAIN_VOLUME]);
104  } else {
105  midi->chnController(chn,CTL_MAIN_VOLUME,chn_controller[chn][CTL_MAIN_VOLUME]);
106  midi->chnController(chn,11,chn_controller[chn][11]);
107  }
108  /*
109  for (int i=0;i<256;i++)
110  midi->chnController(chn,i,chn_controller[chn][i]);
111  */
112  }
113  midi->tmrSetTempo(tempo);
114  midi->sync();
115 }
DeviceManager
MIDI Device Manager class .
Definition: deviceman.h:48
DeviceManager::chnPitchBender
void chnPitchBender(uchar chn, uchar lsb, uchar msb)
Changes the Pitch Bender value on a MIDI channel.
Definition: deviceman.cpp:521
DeviceManager::chnPatchChange
void chnPatchChange(uchar chn, uchar patch)
Changes the patch (instrument) on a MIDI channel.
Definition: deviceman.cpp:511
DeviceManager::chnController
void chnController(uchar chn, uchar ctl, uchar v)
Sends a Controller event to a MIDI channel.
Definition: deviceman.cpp:526
DeviceManager::chnPressure
void chnPressure(uchar chn, uchar vel)
Changes the Pressure (Aftertouch) on a MIDI channel.
Definition: deviceman.cpp:516
DeviceManager::sync
void sync(bool f=0)
Synchronizes with the MIDI buffer.
Definition: deviceman.cpp:632
DeviceManager::tmrSetTempo
void tmrSetTempo(int v)
Sets the tempo which will be used to convert between ticks and milliseconds.
Definition: deviceman.cpp:553
MidiStatus::chnPitchBender
void chnPitchBender(uchar chn, uchar lsb, uchar msb)
Stores a new pitch bender value in channel chn.
Definition: midistat.cpp:71
MidiStatus::~MidiStatus
~MidiStatus()
Destructor.
Definition: midistat.cpp:54
MidiStatus::chnPressure
void chnPressure(uchar chn, uchar vel)
Stores a new channel pressure value in channel chn.
Definition: midistat.cpp:66
MidiStatus::tmrSetTempo
void tmrSetTempo(int v)
Sets the tempo.
Definition: midistat.cpp:84
MidiStatus::chnController
void chnController(uchar chn, uchar ctl, uchar v)
Stores a new value for controller ctl in channel chn.
Definition: midistat.cpp:76
MidiStatus::chnPatchChange
void chnPatchChange(uchar chn, uchar patch)
Stores a new patch in channel chn.
Definition: midistat.cpp:61
MidiStatus::MidiStatus
MidiStatus()
Constructor.
Definition: midistat.cpp:36
MidiStatus::sendData
void sendData(class DeviceManager *midi, int gm=1)
Sends the current MIDI state to the DeviceManager object used as parameter (you should have already s...
Definition: midistat.cpp:89

libtdemid

Skip menu "libtdemid"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libtdemid

Skip menu "libtdemid"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for libtdemid by doxygen 1.9.1
This website is maintained by Timothy Pearson.