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

« back to all changes in this revision

Viewing changes to kmidi/sbktext.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
 * print the sbk/sf2 information
 
3
 *
 
4
 * Copyright (C) 1996,1997 Takashi Iwai
 
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
 
 
21
#include <stdio.h>
 
22
#include <string.h>
 
23
#include "config.h"
 
24
#include "sbk.h"
 
25
#include "sflayer.h"
 
26
 
 
27
static SFInfo sfinfo;
 
28
 
 
29
static char *getname(char *p);
 
30
static void print_sbk(SFInfo *sf, FILE *fout);
 
31
 
 
32
 
 
33
int main(int argc, char **argv)
 
34
{
 
35
        FILE *fp;
 
36
 
 
37
        if (argc < 2) {
 
38
                fprintf(stderr, "usage: sf2text SoundFontFile [textfile]\n");
 
39
                exit(1);
 
40
        }
 
41
 
 
42
        if ((fp = fopen(argv[1], "r")) == NULL) {
 
43
                fprintf(stderr, "can't open SoundFont file %s\n", argv[1]);
 
44
                exit(1);
 
45
        }
 
46
 
 
47
        load_sbk(fp, &sfinfo);
 
48
        fclose(fp);
 
49
 
 
50
        fp = stdout;
 
51
        if (argc >= 3 && (fp = fopen(argv[2], "w")) == NULL) {
 
52
                fprintf(stderr, "can't open text file %s\n", argv[2]);
 
53
                exit(1);
 
54
        }
 
55
        print_sbk(&sfinfo, fp);
 
56
 
 
57
        return 0;
 
58
}
 
59
 
 
60
 
 
61
static char *getname(p)
 
62
        char *p;
 
63
{
 
64
        static char buf[21];
 
65
        strncpy(buf, p, 20);
 
66
        buf[20] = 0;
 
67
        return buf;
 
68
}
 
69
 
 
70
 
 
71
static void print_sbk(SFInfo *sf, FILE *fout)
 
72
{
 
73
        char buf[1000];
 
74
        int i, ninfos;
 
75
        tpresethdr *ip;
 
76
        tinsthdr *tp;
 
77
        tsampleinfo *hp;
 
78
 
 
79
        fprintf(fout, "** SoundFont: %d %d\n", sf->version, sf->minorversion);
 
80
        fprintf(fout, "** SampleData: %d %d\n", (int)sf->samplepos, (int)sf->samplesize);
 
81
 
 
82
        fprintf(fout, "\n** Presets: %d\n", sf->nrpresets-1);
 
83
        for (i = 0, ip = sf->presethdr; i < sf->nrpresets-1; ip++, i++) {
 
84
                int b;
 
85
                fprintf(fout, "[%s] preset=%d bank=%d layer=%d\n",
 
86
                       getname(ip->name), ip->preset, ip->bank,
 
87
                       ip[1].bagNdx - ip->bagNdx);
 
88
                for (b = ip->bagNdx; b < ip[1].bagNdx; b++) {
 
89
                        int g;
 
90
                        fprintf(fout, "    BAG %d\n", sf->presetbag[b+1] - sf->presetbag[b]);
 
91
                        for (g = sf->presetbag[b]; g < sf->presetbag[b+1]; g++) {
 
92
                                sbk_to_text(buf, sf->presetgen[g].oper,
 
93
                                            sf->presetgen[g].amount, sf);
 
94
                                fprintf(fout, "    %s\n", buf);
 
95
                        }
 
96
                }
 
97
        }
 
98
 
 
99
        fprintf(fout, "\n** Instruments: %d\n", sf->nrinsts-1);
 
100
        for (i = 0, tp = sf->insthdr; i < sf->nrinsts-1; tp++, i++) {
 
101
                int b;
 
102
                fprintf(fout, "[%s] layer=%d\n", getname(tp->name), tp[1].bagNdx - tp->bagNdx);
 
103
                for (b = tp->bagNdx; b < tp[1].bagNdx; b++) {
 
104
                        int g;
 
105
                        fprintf(fout, "    BAG %d\n", sf->instbag[b+1] - sf->instbag[b]);
 
106
                        for (g = sf->instbag[b]; g < sf->instbag[b+1]; g++) {
 
107
                                sbk_to_text(buf, sf->instgen[g].oper,
 
108
                                            sf->instgen[g].amount, sf);
 
109
                                fprintf(fout, "    %s\n", buf);
 
110
                        }
 
111
                }
 
112
        }
 
113
 
 
114
        if (sf->version == 1)
 
115
                ninfos = sf->nrinfos;
 
116
        else
 
117
                ninfos = sf->nrinfos - 1;
 
118
        fprintf(fout, "\n** SampleInfo: %d\n", ninfos);
 
119
        for (i = 0, hp = sf->sampleinfo; i < ninfos; hp++, i++) {
 
120
                fprintf(fout, "[%s] start=%lx end=%lx startloop=%lx endloop=%lx\n",
 
121
                       sf->samplenames[i].name, hp->startsample, hp->endsample,
 
122
                       hp->startloop, hp->endloop);
 
123
                if (sf->version > 1) {
 
124
                        fprintf(fout, "    rate=%d, pitch=%d:%d, link=%d, type=%x\n",
 
125
                               (int)hp->samplerate,
 
126
                               hp->originalPitch,
 
127
                               hp->pitchCorrection,
 
128
                               hp->samplelink,
 
129
                               hp->sampletype);
 
130
                }
 
131
        }
 
132
}