~jari-tasankokaiku/+junk/hrja

« back to all changes in this revision

Viewing changes to main.cpp

  • Committer: Jari Suominen
  • Date: 2012-05-29 09:22:43 UTC
  • Revision ID: jari@tasankokaiku.com-20120529092243-mo3irz1umyzc98i6
some cleaning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*===============================================================================================
2
 
 SimpleEvent Example
3
 
 Copyright (c), Firelight Technologies Pty, Ltd 2004-2010.
4
 
 
5
 
 Demonstrates basic usage of FMOD's data-driven event library (fmod_event.dll)
 
2
 Copyright (c), Jari Suominen 2008-2012.
6
3
===============================================================================================*/
7
4
//#include "../../../examples/common/wincompat.h"
8
5
 
12
9
#include <alsa/asoundlib.h>
13
10
#include <fmodex/fmod_event.hpp>
14
11
#include <fmodex/fmod_errors.h>
15
 
#include "./banks/jarse.h"
 
12
#include "jarse.h"
16
13
#include <stdint.h>   /* Standard types */
17
14
#include <string.h>   /* String function definitions */
18
15
#include <fcntl.h>    /* File control definitions */
21
18
#include <sys/ioctl.h>
22
19
#include <getopt.h>
23
20
 
24
 
void usage(void);
25
 
int serialport_init(const char* serialport, int baud);
26
 
int serialport_writebyte(int fd, uint8_t b);
27
 
int serialport_write(int fd, const char* str);
28
 
int serialport_read_until(int fd, char* buf, char until);
29
 
void working(int i);
30
 
void write_int(int a, int b);
31
 
void update();
32
21
 
33
22
bool variationActive = false;
34
23
int fd;
69
58
}
70
59
 
71
60
 
72
 
void ERRCHECK(FMOD_RESULT result)
73
 
{
74
 
    if (result != FMOD_OK)
75
 
    {
76
 
        printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
77
 
        exit(-1);
78
 
    }
 
61
void ERRCHECK(FMOD_RESULT result) {
 
62
  if (result != FMOD_OK) {
 
63
    printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
 
64
    exit(-1);
 
65
  }
79
66
}
80
67
 
81
68
void next() {
82
 
        eventsystem->update();
83
 
        musicsystem->setParameterValue(MUSICPARAM_JARSE_VARIATION,1);
84
 
        musicsystem->setParameterValue(MUSICPARAM_JARSE_NEXT,0);
85
 
        printf("NEXT!\n");
86
 
        //write_int(49,fd);
87
 
        fflush(stdout);
 
69
  eventsystem->update();
 
70
  musicsystem->setParameterValue(MUSICPARAM_JARSE_VARIATION,1);
 
71
  musicsystem->setParameterValue(MUSICPARAM_JARSE_NEXT,0);
 
72
  printf("NEXT!\n");
 
73
  fflush(stdout);
88
74
}
89
75
 
90
76
void variation() {
91
 
        eventsystem->update();
92
 
        musicsystem->setParameterValue(MUSICPARAM_JARSE_NEXT,1);
93
 
        musicsystem->setParameterValue(MUSICPARAM_JARSE_VARIATION,0);
94
 
        printf("VARIATION!\n");
95
 
        //write_int(50,fd);
96
 
        fflush(stdout);
 
77
  eventsystem->update();
 
78
  musicsystem->setParameterValue(MUSICPARAM_JARSE_NEXT,1);
 
79
  musicsystem->setParameterValue(MUSICPARAM_JARSE_VARIATION,0);
 
80
  printf("VARIATION!\n");
 
81
  fflush(stdout);
97
82
}
98
83
 
99
84
void reset() {
100
 
        eventsystem->update();
101
 
        musicsystem->setParameterValue(MUSICPARAM_JARSE_NEXT,1);
102
 
        musicsystem->setParameterValue(MUSICPARAM_JARSE_VARIATION,1);
103
 
        printf("RESET!\n");
104
 
        //write_int(50,fd);
105
 
        fflush(stdout);
 
85
  eventsystem->update();
 
86
  musicsystem->setParameterValue(MUSICPARAM_JARSE_NEXT,1);
 
87
  musicsystem->setParameterValue(MUSICPARAM_JARSE_VARIATION,1);
 
88
  printf("RESET!\n");
 
89
  fflush(stdout);
106
90
}
107
91
 
108
92
FMOD_RESULT resetParams(FMOD_MUSIC_CALLBACKTYPE type, void * p, void * p2, void * ud) {
115
99
        int operation, channel, param1, param2;
116
100
 
117
101
        if (type==FMOD_MUSIC_CALLBACKTYPE_BEAT) {
118
 
                snd_seq_ev_set_noteon(&ev, 10, 11, 11);
 
102
//              snd_seq_ev_set_noteon(&ev, 10, 11, 11);
119
103
                snd_seq_ev_set_noteon(&ev, 6, 0, 0);
120
104
                printf("BEAT!\n");
121
105
                fflush(stdout);
207
191
}
208
192
 
209
193
 
210
 
int main(int argc, char *argv[])
211
 
{
212
 
    
213
 
    FMOD::System      *system;
214
 
    FMOD::Event       *event;;
215
 
    FMOD_RESULT        result;
216
 
    int                key;
217
 
 
218
 
    printf("======================================================================\n");
219
 
    printf("Hurja. Experimental sampler. Copyright (c) Jari Suominen 2010-2011.\n");
220
 
    printf("======================================================================\n");
221
 
 
222
 
    ERRCHECK(result = FMOD::EventSystem_Create(&eventsystem));
223
 
    eventsystem->getSystemObject(&system);
224
 
    ERRCHECK(result = system->setOutput(FMOD_OUTPUTTYPE_ALSA));
225
 
    ERRCHECK(result = system->setSpeakerMode(FMOD_SPEAKERMODE_5POINT1)); 
226
 
    ERRCHECK(result = eventsystem->init(64, FMOD_INIT_NORMAL, 0, FMOD_EVENT_INIT_NORMAL));
227
 
    ERRCHECK(result = eventsystem->getMusicSystem(&musicsystem));
228
 
    //ERRCHECK(result = eventsystem->setMediaPath("./banks/"));
229
 
    ERRCHECK(result = eventsystem->setMediaPath(argv[1]));
230
 
    ERRCHECK(result = eventsystem->load("jarse.fev", 0, 0));
231
 
    
232
 
    int npfd;
233
 
    struct pollfd *pfd;
234
 
 
235
 
    seq_handle = open_seq();
236
 
    npfd = snd_seq_poll_descriptors_count(seq_handle, POLLIN);
237
 
    pfd = (struct pollfd *)alloca(npfd * sizeof(struct pollfd));
238
 
    snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN);
239
 
 
240
 
    printf("======================================================================\n");
241
 
    printf("Press ESC   to quit\n");
242
 
    printf("======================================================================\n");
243
 
 
244
 
    musicsystem->setParameterValue(MUSICPARAM_JARSE_NEXT,1);
245
 
    musicsystem->setParameterValue(MUSICPARAM_JARSE_VARIATION,1);
246
 
    musicsystem->setCallback(resetParams,0);
247
 
 
248
 
        //ERRCHECK(result = musicsystem->promptCue(MUSICCUE_JARSE_KORPIKUUSEN));
249
 
 
250
 
    char b[2];
251
 
    key = 0;
252
 
 
253
 
    do { // MAIN LOOP
254
 
        
255
 
        
256
 
        if (poll(pfd,npfd, 100) > 0) {
257
 
                midi_action(seq_handle);
258
 
        }
259
 
 
260
 
        usleep (10);
261
 
        
262
 
        //ERRCHECK(result = musicsystem->promptCue(MUSICCUE_JARSE_BO));
263
 
                        
264
 
                
265
 
 
266
 
        ERRCHECK(result = eventsystem->update());
267
 
        fflush(stdout);
268
 
 
269
 
    } while (1==1);
270
 
 
271
 
    ERRCHECK(result = eventsystem->release());
272
 
    return 0;
 
194
int main(int argc, char *argv[]) {
 
195
    
 
196
  FMOD::System      *system;
 
197
  FMOD::Event       *event;;
 
198
  FMOD_RESULT        result;
 
199
  int                key;
 
200
 
 
201
  printf("======================================================================\n");
 
202
  printf("Hurja. Experimental sampler. Copyright (c) Jari Suominen 2010-2011.\n");
 
203
  printf("======================================================================\n");
 
204
 
 
205
  ERRCHECK(result = FMOD::EventSystem_Create(&eventsystem));
 
206
  eventsystem->getSystemObject(&system);
 
207
  ERRCHECK(result = system->setOutput(FMOD_OUTPUTTYPE_ALSA));
 
208
  ERRCHECK(result = system->setSpeakerMode(FMOD_SPEAKERMODE_5POINT1)); 
 
209
  ERRCHECK(result = eventsystem->init(64, FMOD_INIT_NORMAL, 0, FMOD_EVENT_INIT_NORMAL));
 
210
  ERRCHECK(result = eventsystem->getMusicSystem(&musicsystem));
 
211
  //ERRCHECK(result = eventsystem->setMediaPath("./banks/"));
 
212
  ERRCHECK(result = eventsystem->setMediaPath(argv[1]));
 
213
  ERRCHECK(result = eventsystem->load("jarse.fev", 0, 0));
 
214
    
 
215
  int npfd;
 
216
  struct pollfd *pfd;
 
217
 
 
218
  seq_handle = open_seq();
 
219
  npfd = snd_seq_poll_descriptors_count(seq_handle, POLLIN);
 
220
  pfd = (struct pollfd *)alloca(npfd * sizeof(struct pollfd));
 
221
  snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN);
 
222
 
 
223
  printf("======================================================================\n");
 
224
  printf("Press ESC   to quit\n");
 
225
  printf("======================================================================\n");
 
226
 
 
227
  musicsystem->setParameterValue(MUSICPARAM_JARSE_NEXT,1);
 
228
  musicsystem->setParameterValue(MUSICPARAM_JARSE_VARIATION,1);
 
229
  musicsystem->setCallback(resetParams,0);
 
230
 
 
231
  char b[2];
 
232
  key = 0;
 
233
 
 
234
  do { // MAIN LOOP
 
235
                
 
236
    if (poll(pfd,npfd, 100) > 0) {
 
237
      midi_action(seq_handle);
 
238
    }
 
239
 
 
240
    usleep (10);
 
241
        
 
242
    ERRCHECK(result = eventsystem->update());
 
243
    fflush(stdout);
 
244
 
 
245
  } while (1==1);
 
246
 
 
247
  ERRCHECK(result = eventsystem->release());
 
248
  return 0;
273
249
}