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

« back to all changes in this revision

Viewing changes to kmidi/dumb_c.cpp

  • 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
    TiMidity -- Experimental MIDI to WAVE converter
 
4
    Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
 
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
    dumb_c.c
 
21
    Minimal control mode -- no interaction, just prints out messages.
 
22
    */
 
23
 
 
24
#include <stdio.h>
 
25
#include <stdlib.h>
 
26
#include <stdarg.h>
 
27
 
 
28
#include "config.h"
 
29
#include "common.h"
 
30
#include "output.h"
 
31
#include "controls.h"
 
32
#include "instrum.h"
 
33
#include "playmidi.h"
 
34
 
 
35
static void ctl_refresh(void);
 
36
static void ctl_total_time(uint32 tt);
 
37
static void ctl_master_volume(int mv);
 
38
static void ctl_file_name(char *name);
 
39
static void ctl_current_time(uint32 ct);
 
40
static void ctl_note(int v);
 
41
static void ctl_program(int ch, int val, const char *name);
 
42
static void ctl_volume(int ch, int val);
 
43
static void ctl_expression(int ch, int val);
 
44
static void ctl_panning(int ch, int val);
 
45
static void ctl_sustain(int ch, int val);
 
46
static void ctl_pitch_bend(int ch, int val);
 
47
static void ctl_reset(void);
 
48
static int ctl_open(int using_stdin, int using_stdout);
 
49
static void ctl_close(void);
 
50
static int ctl_read(int32 *valp);
 
51
static int cmsg(int type, int verbosity_level, const char *fmt, ...);
 
52
 
 
53
/**********************************/
 
54
/* export the interface functions */
 
55
 
 
56
#define ctl dumb_control_mode
 
57
 
 
58
ControlMode ctl= 
 
59
{
 
60
  "dumb interface", 'd',
 
61
  1,0,0,
 
62
  ctl_open,dumb_pass_playing_list, ctl_close, ctl_read, cmsg,
 
63
  ctl_refresh, ctl_reset, ctl_file_name, ctl_total_time, ctl_current_time, 
 
64
  ctl_note, 
 
65
  ctl_master_volume, ctl_program, ctl_volume, 
 
66
  ctl_expression, ctl_panning, ctl_sustain, ctl_pitch_bend
 
67
};
 
68
 
 
69
static FILE *infp;  /* infp isn't actually used yet */
 
70
static FILE *outfp;
 
71
 
 
72
static int ctl_open(int using_stdin, int using_stdout)
 
73
{
 
74
  infp = stdin; outfp = stdout;
 
75
  if (using_stdin && using_stdout)
 
76
    infp=outfp=stderr;
 
77
  else if (using_stdout)
 
78
    outfp=stderr;
 
79
  else if (using_stdin)
 
80
    infp=stdout;
 
81
 
 
82
  ctl.opened=1;
 
83
  return 0;
 
84
}
 
85
 
 
86
static void ctl_close(void)
 
87
 
88
  fflush(outfp);
 
89
  ctl.opened=0;
 
90
}
 
91
 
 
92
static int ctl_read(int32 *valp)
 
93
{
 
94
  return RC_NONE;
 
95
}
 
96
 
 
97
static int cmsg(int type, int verbosity_level, const char *fmt, ...)
 
98
{
 
99
  va_list ap;
 
100
  int flag_newline = 1;
 
101
#ifdef ADAGIO
 
102
  if (interactive) return 0;
 
103
#endif
 
104
  if ((type==CMSG_TEXT || type==CMSG_INFO || type==CMSG_WARNING) &&
 
105
      ctl.verbosity<verbosity_level)
 
106
    return 0;
 
107
  if (*fmt == '~')
 
108
    {
 
109
      flag_newline = 0;
 
110
      fmt++;
 
111
    }
 
112
  va_start(ap, fmt);
 
113
  if (!ctl.opened)
 
114
    {
 
115
      vfprintf(stderr, fmt, ap);
 
116
      if (flag_newline) fprintf(stderr, "\n");
 
117
    }
 
118
  else
 
119
    {
 
120
      vfprintf(outfp, fmt, ap);
 
121
      if (flag_newline) fprintf(outfp, "\n");
 
122
    }
 
123
  va_end(ap);
 
124
  if (!flag_newline) fflush(outfp);
 
125
  return 0;
 
126
}
 
127
 
 
128
static void ctl_refresh(void) { }
 
129
 
 
130
static void ctl_total_time(uint32 tt)
 
131
{
 
132
  uint32 mins, secs;
 
133
  if (ctl.trace_playing)
 
134
    {
 
135
      secs=tt/play_mode->rate;
 
136
      mins=secs/60;
 
137
      secs-=mins*60;
 
138
      fprintf(outfp, "Total playing time: %3ld min %02ld s\n", mins, secs);
 
139
    }
 
140
}
 
141
 
 
142
static void ctl_master_volume(int mv) { mv = 0; }
 
143
 
 
144
static void ctl_file_name(char *name)
 
145
{
 
146
  if (ctl.verbosity>=0 || ctl.trace_playing)
 
147
    fprintf(outfp, "Playing %s\n", name);
 
148
}
 
149
 
 
150
static void ctl_current_time(uint32 ct)
 
151
{
 
152
  uint32 mins, secs;
 
153
  if (ctl.trace_playing)
 
154
    {
 
155
      secs=ct/play_mode->rate;
 
156
      mins=secs/60;
 
157
      secs-=mins*60;
 
158
      fprintf(outfp, "\r%3ld:%02ld", mins, secs);
 
159
      fflush(outfp);
 
160
    }
 
161
}
 
162
 
 
163
static void ctl_note(int v) { v = 0; }
 
164
 
 
165
static void ctl_program(int ch, int val, const char *name) { ch = val = 0; name = 0; }
 
166
 
 
167
static void ctl_volume(int ch, int val) { ch = val = 0; }
 
168
 
 
169
static void ctl_expression(int ch, int val) { ch = val = 0; }
 
170
 
 
171
static void ctl_panning(int ch, int val) { ch = val = 0; }
 
172
 
 
173
static void ctl_sustain(int ch, int val) { ch = val = 0; }
 
174
 
 
175
static void ctl_pitch_bend(int ch, int val) { ch = val = 0; }
 
176
 
 
177
static void ctl_reset(void) {}