File: a_sequencer.c

package info (click to toggle)
kobodeluxe 0.5.1-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 4,324 kB
  • ctags: 4,853
  • sloc: ansic: 18,747; cpp: 18,203; sh: 3,191; makefile: 160
file content (116 lines) | stat: -rw-r--r-- 2,520 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*(LGPL)
---------------------------------------------------------------------------
	a_sequencer.c - MIDI Sequencer
---------------------------------------------------------------------------
 * Copyright (C) 2002, David Olofson
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "a_globals.h"
#include "a_struct.h"

#include "a_sequencer.h"
#include "a_midisock.h"

/*
 * Temporary MIDI playback hack.
 *
 * Only one sequence at a time, and it uses the
 * same midisock as the external MIDI input.
 */

midi_player_t *midiplayer = 0;
static float fs = 44100;


int sequencer_open(midisock_t *ms, float framerate)
{
	aev_client("sequencer_open()");
	fs = framerate;
#if 1
	midiplayer = mp_open(ms);
#else
	midiplayer = mp_open(&monitor_midisock);
#endif
	return (midiplayer != 0);
}


void sequencer_close(void)
{
	aev_client("sequencer_close()");
	if(!midiplayer)
		return;

	mp_close(midiplayer);
	midiplayer = 0;
}


int sequencer_play(midi_file_t *mf, int tag, int pitch, int volume)
{
	aev_client("sequencer_play()");
	if(!midiplayer)
		return -1;

	midiplayer->pitch = pitch - (60 << 16);
	mp_select(midiplayer, mf);
	return 0;
}


void sequencer_stop(int tag)
{
	aev_client("sequencer_stop()");
	if(!midiplayer)
		return;

	mp_stop(midiplayer);
}


int sequencer_playing(int tag)
{
	if(!midiplayer)
		return 0;

	return (midiplayer->mf != 0);
}


void sequencer_process(unsigned frames)
{
	int i;
	aev_client("sequencer_process()");
	if(!midiplayer)
		return;

	if(mp_play(midiplayer, (float)frames / fs))
		return;

	for(i = 0; i < AUDIO_MAX_CHANNELS; ++i)
	{
		int wave;
		if(!channeltab[i].playing)
			continue;
		wave = patchtab[channeltab[i].ctl[ACC_PATCH]].param[APP_WAVE];
		if((wave < 0) || (wave >= AUDIO_MAX_WAVES))
			continue;
		if(AF_MIDI != wavetab[wave].format)
			continue;
		channeltab[i].playing = 0;
	}
}