1/*
2
3main.cpp
4
5Copyright (c) 2002 OpenBeOS.
6
7Test application plays a midi file via a BMidiLocalProducer.
8
9Authors:
10	Michael Pfeiffer
11	Paul Stadler
12
13Permission is hereby granted, free of charge, to any person obtaining a copy of
14this software and associated documentation files (the "Software"), to deal in
15the Software without restriction, including without limitation the rights to
16use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
17of the Software, and to permit persons to whom the Software is furnished to do
18so, subject to the following conditions:
19
20The above copyright notice and this permission notice shall be included in all
21copies or substantial portions of the Software.
22
23THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29THE SOFTWARE.
30
31*/
32
33#include <Application.h>
34#include <MidiStore.h>
35#include <Entry.h>
36#include <stdio.h>
37
38#include "MidiDelay.h"
39#include "Midi1To2Bridge.h"
40
41int main(int argc, char *argv[]) {
42	if (argc != 2) {
43		fprintf(stderr, "Error missing parameter!\n%s midi_file\n", argv[0]);
44		return -1;
45	}
46
47	BEntry entry(argv[1],true);
48	if(!entry.Exists()) {
49		fprintf(stderr, "File does not exist!\n");
50		return -1;
51	}
52
53	new BApplication("application/vnd.obos-midiplayer");
54	BMidiStore     store;
55	MidiDelay      delay;
56	Midi1To2Bridge bridge("MidiPlayer output");
57
58	entry_ref e_ref;
59	entry.GetRef(&e_ref);
60	store.Import(&e_ref);
61	store.Connect(&delay);
62	delay.Connect(&bridge);
63	// Use PatchBay to connect the MidiProducer with a MidiConsumer
64	// (or just MidiSynth 1.6)
65	printf("Connect MidiPlayer output to a MidiConsumer.\n""Hit return to start! "); getchar();
66	store.Start();
67	while(store.IsRunning()) {
68		snooze(100000);
69	}
70	store.Stop();
71	store.Disconnect(&delay);
72	delay.Disconnect(&bridge);
73}
74