[go: up one dir, main page]

File: seq.c

package info (click to toggle)
solfege 3.10.3-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 12,408 kB
  • ctags: 4,270
  • sloc: python: 22,161; xml: 7,536; ansic: 4,442; makefile: 685; sh: 308
file content (111 lines) | stat: -rw-r--r-- 2,864 bytes parent folder | download | duplicates (10)
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

#define SEQUENCER_DEV "/dev/sequencer2"
#include <linux/soundcard.h>
#include <linux/awe_voice.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <assert.h>

int devnum = 0;
int seqfd = -1;
SEQ_DEFINEBUF(2048);

void seqbuf_dump()
{
  assert(seqfd != -1);
  if (_seqbufptr)
    if (write (seqfd, _seqbuf, _seqbufptr) == -1) 
      perror("solfege_c_midi.seqbuf_dump.Can't write to MIDI device");   
  _seqbufptr = 0;
}


void seq_reset() {
        ioctl(seqfd, SNDCTL_SEQ_RESET);
        seqbuf_dump();
}
void initialize_sound() {
        if ((seqfd = open(SEQUENCER_DEV, O_WRONLY, 0)) < 0) {
                perror("open" SEQUENCER_DEV);
                exit(-1);
        }
}
void close_sound() {
        close(seqfd);
}

/*
 * This sounds like this om my linux 2.4.0 with sb pnp32 soundcard
 * 1. The first tone starts. 
 * 2. The second tone starts.
 * 3. The second tone stops.
 * 4. The first tone last forever (that is until we close the device)
 *
 * If I use chn 0 on the first and chn 1 on the second note, it works
 * ok. The OSS Programming guide (4front) don't say anywhere that I must
 * use chn 0 before chn 1. What am I missing??
 */
void test1() {
        seq_reset();
        SEQ_START_TIMER();
        SEQ_SET_PATCH(devnum, 0, 58);
        SEQ_SET_PATCH(devnum, 1, 60);

        SEQ_START_NOTE(devnum, 1, 50, 100);
        SEQ_DELTA_TIME(60);
        SEQ_STOP_NOTE(devnum, 1, 50, 100);
        
        SEQ_START_NOTE(devnum, 0, 51, 100);
        SEQ_DELTA_TIME(60);
        SEQ_STOP_NOTE(devnum, 0, 51, 100);
        SEQ_STOP_TIMER();
        SEQ_DUMPBUF();
}

/*
 * The 31 first notes are stopped as they should, but after that, the
 * notes are not stopped by the SEQ_STOP_NOTE macro
 **/
void test2() {
        int i;
        seq_reset();
        SEQ_START_TIMER();
        SEQ_SET_PATCH(devnum, 0, 58);
        SEQ_SET_PATCH(devnum, 1, 66);
        for (i = 30; i < 63 ; i = i + 2) {
                SEQ_START_NOTE(devnum, 0, i, 100);
                SEQ_DELTA_TIME(20);
                SEQ_STOP_NOTE(devnum, 0, i, 100);
                SEQ_START_NOTE(devnum, 1, i + 1, 100);
                SEQ_DELTA_TIME(20);
                SEQ_STOP_NOTE(devnum, 1, i + 1, 100);
        }
        SEQ_DUMPBUF();
}
void test3() {
        seq_reset();
        SEQ_START_TIMER();
        SEQ_SET_PATCH(devnum, 0, 58);
        SEQ_SET_PATCH(devnum, 1, 60);

        SEQ_START_NOTE(devnum, 0, 50, 100);
        SEQ_DELTA_TIME(60);
        SEQ_STOP_NOTE(devnum, 0, 50, 100);
        
        SEQ_START_NOTE(devnum, 0, 51, 100);
        SEQ_START_NOTE(devnum, 1, 51, 100);
        SEQ_DELTA_TIME(60);
        SEQ_STOP_NOTE(devnum, 0, 51, 100);
        SEQ_STOP_NOTE(devnum, 1, 51, 100);
        SEQ_STOP_TIMER();
        SEQ_DUMPBUF();
}


int main() {
        initialize_sound();
        test3();
        sleep(3);
        close_sound();
}