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

« back to all changes in this revision

Viewing changes to arts/modules/synth_midi_debug_impl.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
    Copyright (C) 2000 Jeff Tranter
 
4
                  tranter@pobox.com
 
5
 
 
6
              (C) 1998 Stefan Westerfeld
 
7
                  stefan@space.twc.de
 
8
 
 
9
    This program is free software; you can redistribute it and/or modify
 
10
    it under the terms of the GNU General Public License as published by
 
11
    the Free Software Foundation; either version 2 of the License, or
 
12
    (at your option) any later version.
 
13
 
 
14
    This program is distributed in the hope that it will be useful,
 
15
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
    GNU General Public License for more details.
 
18
 
 
19
    You should have received a copy of the GNU General Public License
 
20
    along with this program; if not, write to the Free Software
 
21
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
22
 
 
23
    */
 
24
 
 
25
#include <stdio.h>
 
26
#include "debug.h"
 
27
#include "artsmodules.h"
 
28
#include "stdsynthmodule.h"
 
29
 
 
30
using namespace Arts;
 
31
 
 
32
class Synth_MIDI_DEBUG_impl : virtual public Synth_MIDI_DEBUG_skel,
 
33
                                                        virtual public StdSynthModule
 
34
{
 
35
        SystemMidiTimer timer;
 
36
        MidiClient client;
 
37
public:
 
38
        Synth_MIDI_DEBUG self() { return Synth_MIDI_DEBUG::_from_base(_copy()); }
 
39
 
 
40
        void streamInit()
 
41
        {
 
42
                printf("MIDI_DEBUG: streamInit\n");
 
43
                MidiManager manager = Reference("global:Arts_MidiManager");
 
44
                if(!manager.isNull())
 
45
                {
 
46
                        client = manager.addClient(mcdRecord,mctDestination,"midi debug",
 
47
                                                                                        "Arts::Synth_MIDI_DEBUG");
 
48
                        client.addInputPort(self());
 
49
                }
 
50
                else
 
51
                        arts_warning("Synth_MIDI_DEBUG: no midi manager found "
 
52
                                                 "- not registered");
 
53
        }
 
54
 
 
55
        void processEvent(const MidiEvent& event)
 
56
        {
 
57
                printf("MIDI_DEBUG: scheduling event at %ld.%ld\n",
 
58
                                                        event.time.sec, event.time.usec);
 
59
                timer.queueEvent(self(),event);
 
60
        }
 
61
        void processCommand(const MidiCommand& command)
 
62
        {
 
63
                mcopbyte channel = command.status & mcsChannelMask;
 
64
                switch(command.status & mcsCommandMask)
 
65
                {
 
66
                        case mcsNoteOn:  printf("MIDI_DEBUG: note on  channel %d, "
 
67
                                                                   "note %d, velocity %d\n", channel,
 
68
                                                                   command.data1, command.data2);
 
69
                                                break;
 
70
                        case mcsNoteOff: printf("MIDI_DEBUG: note off channel %d, "
 
71
                                                                   "note %d, velocity %d\n", channel,
 
72
                                                                   command.data1, command.data2);
 
73
                                                break;
 
74
                }
 
75
        }
 
76
 
 
77
        TimeStamp time()
 
78
        {
 
79
                timeval tv;
 
80
                gettimeofday(&tv, 0);
 
81
                return TimeStamp(tv.tv_sec, tv.tv_usec);
 
82
        }
 
83
 
 
84
};
 
85
 
 
86
REGISTER_IMPLEMENTATION(Synth_MIDI_DEBUG_impl);