diff options
| author | deva <deva> | 2011-07-15 13:02:33 +0000 | 
|---|---|---|
| committer | deva <deva> | 2011-07-15 13:02:33 +0000 | 
| commit | cd0e36773992e26985bdec1f7a5341f83fa3e521 (patch) | |
| tree | 4710fb3f2465f4b464f5f6176261a67cfde2e46e /drumgizmo | |
| parent | e190d38057892b69246391841b234a368bc2b4ad (diff) | |
New input/output plugin architecture. New LV2 plugin.
Diffstat (limited to 'drumgizmo')
30 files changed, 3052 insertions, 0 deletions
| diff --git a/drumgizmo/Makefile.am b/drumgizmo/Makefile.am new file mode 100644 index 0000000..dbbd6e3 --- /dev/null +++ b/drumgizmo/Makefile.am @@ -0,0 +1,43 @@ +SUBDIRS = input output + +bin_PROGRAMS = drumgizmo + +drumgizmo_LDADD = $(SNDFILE_LIBS) $(PTHREAD_LIBS) $(EXPAT_LIBS) -ldl + +drumgizmo_CXXFLAGS = $(SNDFILE_CXXFLAGS) $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/src + +drumgizmo_SOURCES = \ +	audioinputenginedl.cc \ +	audiooutputenginedl.cc \ +	drumgizmoc.cc \ +	$(top_srcdir)/src/audiofile.cc \ +	$(top_srcdir)/src/channel.cc \ +	$(top_srcdir)/src/channelmixer.cc \ +	$(top_srcdir)/src/drumgizmo.cc \ +	$(top_srcdir)/src/drumkit.cc \ +	$(top_srcdir)/src/drumkitparser.cc \ +	$(top_srcdir)/src/events.cc \ +	$(top_srcdir)/src/instrument.cc \ +	$(top_srcdir)/src/instrumentparser.cc \ +	$(top_srcdir)/src/midimapper.cc \ +	$(top_srcdir)/src/mutex.cc \ +	$(top_srcdir)/src/path.cc \ +	$(top_srcdir)/src/sample.cc \ +	$(top_srcdir)/src/saxparser.cc \ +	$(top_srcdir)/src/thread.cc \ +	$(top_srcdir)/src/velocity.cc + +EXTRA_DIST = \ +	audioinputenginedl.h \ +	audiooutputenginedl.h + +################ +# Test Section # +################ + +TEST_SOURCE_DEPS = ${drumgizmo_SOURCES} ${EXTRA_DIST} +TEST_SCRIPT_DIR = $(top_srcdir)/tools + +include ${TEST_SCRIPT_DIR}/Makefile.am.test + +include Makefile.am.test diff --git a/drumgizmo/audioinputenginedl.cc b/drumgizmo/audioinputenginedl.cc new file mode 100644 index 0000000..3b2a483 --- /dev/null +++ b/drumgizmo/audioinputenginedl.cc @@ -0,0 +1,236 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            audioinputenginedl.cc + * + *  Wed Jul 13 14:39:54 CEST 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include "audioinputenginedl.h" + +#include <stdio.h> + +#include <dlfcn.h> + +#include <config.h> +#include <string.h> +#include <stdlib.h> + +AudioInputEngineDL::AudioInputEngineDL(std::string name) +{ +  std::string plugin = INPUT_PLUGIN_DIR"/lib" + name + ".so"; +  void *lib = dlopen(plugin.c_str(), RTLD_LAZY); +  if(!lib) { +    printf("Cannot load device: %s\n", dlerror()); +    return; +  } + +  i_create = (input_create_func_t) dlsym(lib, "create"); +  const char* dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol create: %s\n", dlsym_error); +    return; +  } + +  i_destroy = (input_destroy_func_t) dlsym(lib, "destroy"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  i_init = (input_init_func_t) dlsym(lib, "init"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  i_setparm = (input_setparm_func_t) dlsym(lib, "setparm"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  i_start = (input_start_func_t) dlsym(lib, "start"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  i_stop = (input_stop_func_t) dlsym(lib, "stop"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  i_pre = (input_pre_func_t) dlsym(lib, "pre"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  i_run = (input_run_func_t) dlsym(lib, "run"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  i_post = (input_post_func_t) dlsym(lib, "post"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  ptr = i_create(); +} + +AudioInputEngineDL::~AudioInputEngineDL() +{ +  i_destroy(ptr); +} + +bool AudioInputEngineDL::init(Instruments &instruments) +{ +  char **n = (char**)malloc(sizeof(char*)*instruments.size()); +  for(size_t i = 0; i < instruments.size(); i++) { +    n[i] = strdup(instruments[i].name().c_str()); +  } + +  bool ret = i_init(ptr, instruments.size(), n); + +  for(size_t i = 0; i < instruments.size(); i++) { +    free(n[i]); +  } +  free(n); + +  return ret; +} + +void AudioInputEngineDL::setParm(std::string parm, std::string value) +{ +  i_setparm(ptr, parm.c_str(), value.c_str()); +} + +bool AudioInputEngineDL::start() +{ +  return i_start(ptr); +} + +void AudioInputEngineDL::stop() +{ +  return i_stop(ptr); +} + +void AudioInputEngineDL::pre() +{ +  return i_pre(ptr); +} + +event_t *AudioInputEngineDL::run(size_t pos, size_t len, size_t *nevents) +{ +  return i_run(ptr, pos, len, nevents); +} + +void AudioInputEngineDL::post() +{ +  return i_post(ptr); +} + +//#include "audioinputenginedummy.h" +//#include "audioinputenginejackmidi.h" +//#include "audioinputenginemidifile.h" + +/* + +typedef Device* (*create_func_t)(void); +typedef void (*destroy_func_t)(Device*); + +struct device_t { +  Device* dev; +  destroy_func_t destroyer; +  void* lib; +}; + +int load_shared_device(device_t &dev, std::string devlib, +                             std::string devfile, ConfMap devconfmap) { +  // load library +  dev.lib = dlopen(devlib.c_str(), RTLD_LAZY); +  if(!dev.lib ) { +    printf("Cannot load device: %s\n", dlerror()); +    return -1; +  } + +  create_func_t create_device = (create_func_t) dlsym(dev.lib, "create"); +  const char* dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol create: %s\n", dlsym_error); +    return -1; +  } + +  dev.destroyer = (destroy_func_t) dlsym(dev.lib, "destroy"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return -1; +  } + +  dev.dev = create_device(); + +  // initialize device  +  DevData devdata = dev.dev->init(devfile, devconfmap); +  if(devdata.retval != DevData::VALUE_SUCCESS) { +    printf("Error while initializing device: %s\n",  devdata.msg.c_str()); +    return -1; +  } + +  return 0; +} + +void unload_shared_device(device_t &dev) { +   +  dev.destroyer(dev.dev); +  dlclose(dev.lib); +} +*/ + +#ifdef TEST_AUDIOINPUTENGINEDL +//Additional dependency files +//deps: +//Required cflags (autoconf vars may be used) +//cflags: +//Required link options (autoconf vars may be used) +//libs: +#include "test.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). + +TEST_END; + +#endif/*TEST_AUDIOINPUTENGINEDL*/ diff --git a/drumgizmo/audioinputenginedl.h b/drumgizmo/audioinputenginedl.h new file mode 100644 index 0000000..b8829e5 --- /dev/null +++ b/drumgizmo/audioinputenginedl.h @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            audioinputenginedl.h + * + *  Wed Jul 13 14:39:54 CEST 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#ifndef __DRUMGIZMO_AUDIOINPUTENGINEDL_H__ +#define __DRUMGIZMO_AUDIOINPUTENGINEDL_H__ + +#include "audioinputengine.h" + +typedef void* (*input_create_func_t)(void); +typedef void (*input_destroy_func_t)(void*); +typedef bool (*input_init_func_t)(void*,int,char**); +typedef void (*input_setparm_func_t)(void*,const char*,const char*); +typedef bool (*input_start_func_t)(void*); +typedef void (*input_stop_func_t)(void*); +typedef void (*input_pre_func_t)(void*); +typedef event_t* (*input_run_func_t)(void*,size_t,size_t,size_t*); +typedef void (*input_post_func_t)(void*); +   +class AudioInputEngineDL : public AudioInputEngine { +public: +  AudioInputEngineDL(std::string name); +  ~AudioInputEngineDL(); + +  bool init(Instruments &instruments); + +  void setParm(std::string parm, std::string value); + +  bool start(); +  void stop(); + +  void pre(); +  event_t *run(size_t pos, size_t len, size_t *nevents); +  void post(); + +private: +  void *ptr; +  input_create_func_t i_create; +  input_destroy_func_t i_destroy; +  input_init_func_t i_init; +  input_setparm_func_t i_setparm; +  input_start_func_t i_start; +  input_stop_func_t i_stop; +  input_pre_func_t i_pre; +  input_run_func_t i_run; +  input_post_func_t i_post; +}; + +#endif/*__DRUMGIZMO_AUDIOINPUTENGINEDL_H__*/ diff --git a/drumgizmo/audiooutputenginedl.cc b/drumgizmo/audiooutputenginedl.cc new file mode 100644 index 0000000..411c14b --- /dev/null +++ b/drumgizmo/audiooutputenginedl.cc @@ -0,0 +1,176 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            audiooutputenginedl.cc + * + *  Wed Jul 13 14:40:01 CEST 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include "audiooutputenginedl.h" + +#include <dlfcn.h> +#include <stdio.h> +#include <config.h> +#include <string.h> + +AudioOutputEngineDL::AudioOutputEngineDL(std::string name) +{ +  std::string plugin = OUTPUT_PLUGIN_DIR"/lib" + name + ".so"; +  void *lib = dlopen(plugin.c_str(), RTLD_LAZY); +  if(!lib) { +    printf("Cannot load device: %s\n", dlerror()); +    return; +  } + +  o_create = (output_create_func_t) dlsym(lib, "create"); +  const char* dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol create: %s\n", dlsym_error); +    return; +  } + +  o_destroy = (output_destroy_func_t) dlsym(lib, "destroy"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  o_init = (output_init_func_t) dlsym(lib, "init"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  o_setparm = (output_setparm_func_t) dlsym(lib, "setparm"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  o_start = (output_start_func_t) dlsym(lib, "start"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  o_stop = (output_stop_func_t) dlsym(lib, "stop"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  o_pre = (output_pre_func_t) dlsym(lib, "pre"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  o_run = (output_run_func_t) dlsym(lib, "run"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  o_post = (output_post_func_t) dlsym(lib, "post"); +  dlsym_error = dlerror(); +  if(dlsym_error) { +    printf("Cannot load symbol destroy: %s\n", dlsym_error); +    return; +  } + +  ptr = o_create(); +} + +AudioOutputEngineDL::~AudioOutputEngineDL() +{ +  o_destroy(ptr); +} + +bool AudioOutputEngineDL::init(Channels channels) +{ +  char **n = (char**)malloc(sizeof(char*)*channels.size()); +  for(size_t i = 0; i < channels.size(); i++) { +    n[i] = strdup(channels[i].name.c_str()); +  } + +  bool ret = o_init(ptr, channels.size(), n); + +  for(size_t i = 0; i < channels.size(); i++) { +    free(n[i]); +  } +  free(n); + +  return ret; +} + +void AudioOutputEngineDL::setParm(std::string parm, std::string value) +{ +  o_setparm(ptr, parm.c_str(), value.c_str()); +} + +bool AudioOutputEngineDL::start() +{ +  return o_start(ptr); +} + +void AudioOutputEngineDL::stop() +{ +  return o_stop(ptr); +} + +void AudioOutputEngineDL::pre(size_t size) +{ +  return o_pre(ptr, size); +} +  +void AudioOutputEngineDL::run(int ch, sample_t *samples, size_t nsamples) +{ +  o_run(ptr, ch, samples, nsamples); +} + +void AudioOutputEngineDL::post(size_t size) +{ +  return o_post(ptr, size); +} + +#ifdef TEST_AUDIOOUTPUTENGINEDL +//Additional dependency files +//deps: +//Required cflags (autoconf vars may be used) +//cflags: +//Required link options (autoconf vars may be used) +//libs: +#include "test.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). + +TEST_END; + +#endif/*TEST_AUDIOOUTPUTENGINEDL*/ diff --git a/drumgizmo/audiooutputenginedl.h b/drumgizmo/audiooutputenginedl.h new file mode 100644 index 0000000..7faa78e --- /dev/null +++ b/drumgizmo/audiooutputenginedl.h @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            audiooutputenginedl.h + * + *  Wed Jul 13 14:40:01 CEST 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#ifndef __DRUMGIZMO_AUDIOOUTPUTENGINEDL_H__ +#define __DRUMGIZMO_AUDIOOUTPUTENGINEDL_H__ + +#include <string> +#include <stdlib.h> +#include <audiotypes.h> + +#include "channel.h" + +#include "audiooutputengine.h" + +typedef void* (*output_create_func_t)(void); +typedef void (*output_destroy_func_t)(void*); +typedef bool (*output_start_func_t)(void*); +typedef void (*output_stop_func_t)(void*); +typedef bool (*output_init_func_t)(void*,int,char**); +typedef void (*output_setparm_func_t)(void*,const char*,const char*); +typedef void (*output_pre_func_t)(void*, size_t); +typedef void (*output_run_func_t)(void*,int,sample_t*,size_t); +typedef void (*output_post_func_t)(void*, size_t); + +class AudioOutputEngineDL : public AudioOutputEngine { +public: +  AudioOutputEngineDL(std::string name); +  ~AudioOutputEngineDL(); + +  bool init(Channels channels); + +  void setParm(std::string parm, std::string value); + +  bool start(); +  void stop(); + +  void pre(size_t nsamples); +  void run(int ch, sample_t *samples, size_t nsamples); +  void post(size_t nsamples); + +private: +  void *ptr; +  output_create_func_t o_create; +  output_destroy_func_t o_destroy; +  output_init_func_t o_init; +  output_setparm_func_t o_setparm; +  output_start_func_t o_start; +  output_stop_func_t o_stop; +  output_pre_func_t o_pre; +  output_run_func_t o_run; +  output_post_func_t o_post; +}; + +#endif/*__DRUMGIZMO_AUDIOOUTPUTENGINEDL_H__*/ diff --git a/drumgizmo/drumgizmoc.cc b/drumgizmo/drumgizmoc.cc new file mode 100644 index 0000000..de16dd9 --- /dev/null +++ b/drumgizmo/drumgizmoc.cc @@ -0,0 +1,257 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            cli.cc + * + *  Thu Sep 16 10:23:22 CEST 2010 + *  Copyright 2010 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include <config.h> +#include <getopt.h> + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include "drumgizmo.h" + +#include "audiooutputenginedl.h" +#include "audioinputenginedl.h" + +#include "event.h" + +static const char version_str[] = +"DrumGizmo v" VERSION "\n" +; + +static const char copyright_str[] = +"Copyright (C) 2008-2011 Bent Bisballe Nyeng - Aasimon.org.\n" +"This is free software.  You may redistribute copies of it under the terms of\n" +"the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n" +"There is NO WARRANTY, to the extent permitted by law.\n" +"\n" +"Written by Bent Bisballe Nyeng (deva@aasimon.org)\n" +; + +static const char usage_str[] = +"Usage: %s [options] drumkitfile\n" +"Options:\n" +"  -p, --preload          Load entire kit audio files into memory (uses ALOT of memory).\n" +"  -i, --inputengine dummy|test|jackmidi|midifile  Use said event input engine.\n" +"  -I, --inputparms parmlist  Set input engine parameters.\n" +"  -o, --outputengine dummy|alsa|jack|sndfile  Use said audio output engine.\n" +"  -O, --outputparms parmlist  Set output engine parameters.\n" +"  -v, --version          Print version information and exit.\n" +"  -h, --help             Print this message and exit.\n" +; + +int main(int argc, char *argv[]) +{ +  int c; + +  std::string outputengine; +  std::string inputengine; +  std::string iparms; +  std::string oparms; +  bool preload = false; + +  int option_index = 0; +  while(1) { +    static struct option long_options[] = { +      {"preload", no_argument, 0, 'p'}, +      {"inputengine", required_argument, 0, 'i'}, +      {"inputparms", required_argument, 0, 'I'}, +      {"outputengine", required_argument, 0, 'o'}, +      {"outputparms", required_argument, 0, 'O'}, +      {"help", no_argument, 0, 'h'}, +      {"version", no_argument, 0, 'v'}, +      {0, 0, 0, 0} +    }; +     +    c = getopt_long (argc, argv, "hvpo:O:i:I:", long_options, &option_index); +     +    if (c == -1) +      break; + +    switch(c) { +    case 'i': +      inputengine = optarg; +      if(inputengine == "help") { +        printf("Available input engines: jackmidi, midifile.\n"); +        return 0; +      } +      break; + +    case 'I': +      iparms = optarg; +      break; + +    case 'o': +      outputengine = optarg; +      if(outputengine == "help") { +        printf("Available output engines: alsa, jack, sndfile.\n"); +        return 0; +      } +      break; + +    case 'O': +      oparms = optarg; +      break; + +    case 'p': +      preload = true; +      break; +  +    case '?': +    case 'h': +      printf("%s", version_str); +      printf(usage_str, argv[0]); +      return 0; + +    case 'v': +      printf("%s", version_str); +      printf("%s", copyright_str); +      return 0; + +    default: +      break; +    } +  } + +  if(inputengine == "") { +    printf("Missing input engine\n"); +    return 1; +  } + +  AudioInputEngine *ie = new AudioInputEngineDL(inputengine); + +  if(ie == NULL) { +    printf("Invalid input engine: %s\n", inputengine.c_str()); +    return 1; +  } + +  { +  std::string parm; +  std::string val; +  bool inval = false; +  for(size_t i = 0; i < iparms.size(); i++) { +    if(iparms[i] == ',') { +      ie->setParm(parm, val); +      parm = ""; +      val = ""; +      inval = false; +      continue; +    } + +    if(iparms[i] == '=') { +      inval = true; +      continue; +    } + +    if(inval) { +      val += iparms[i]; +    } else { +      parm += iparms[i]; +    } +  } +  if(parm != "") ie->setParm(parm, val); +  } + +  if(outputengine == "") { +    printf("Missing output engine\n"); +    return 1; +  } + +  AudioOutputEngine *oe = new AudioOutputEngineDL(outputengine); + +  if(oe == NULL) { +    printf("Invalid output engine: %s\n", outputengine.c_str()); +    return 1; +  } + +  { +  std::string parm; +  std::string val; +  bool inval = false; +  for(size_t i = 0; i < oparms.size(); i++) { +    if(oparms[i] == ',') { +      oe->setParm(parm, val); +      parm = ""; +      val = ""; +      inval = false; +      continue; +    } + +    if(oparms[i] == '=') { +      inval = true; +      continue; +    } + +    if(inval) { +      val += oparms[i]; +    } else { +      parm += oparms[i]; +    } +  } +  if(parm != "") oe->setParm(parm, val); +  } + +  std::string kitfile; + +  if(option_index < argc) { +    printf("non-option ARGV-elements: "); +    while (optind < argc) { +      if(kitfile != "") { +        fprintf(stderr, "Can only handle a single kitfile.\n"); +        printf(usage_str, argv[0]); +        return 1; +      } +      kitfile = argv[optind++]; +    } +    printf("\n"); +  } else { +    fprintf(stderr, "Missing kitfile.\n"); +    printf(usage_str, argv[0]); +    return 1; +  } +   +  printf("Using kitfile: %s\n", kitfile.c_str()); + +  DrumGizmo gizmo(oe, ie); +  if(kitfile == "" || !gizmo.loadkit(kitfile)) { +    printf("Failed to load \"%s\".\n", kitfile.c_str()); +    return 1; +  } + +  if(!gizmo.init(preload)) { +    printf("Failed init drumkit.\n"); +    return 1; +  } + +  gizmo.run(); + +  printf("Quit.\n"); fflush(stdout); + +  delete oe; +  delete ie; + +  return 0; +} diff --git a/drumgizmo/input/Makefile.am b/drumgizmo/input/Makefile.am new file mode 100644 index 0000000..d4bdad8 --- /dev/null +++ b/drumgizmo/input/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = @INPUT_PLUGINS@ diff --git a/drumgizmo/input/dummy/Makefile.am b/drumgizmo/input/dummy/Makefile.am new file mode 100644 index 0000000..10bd70f --- /dev/null +++ b/drumgizmo/input/dummy/Makefile.am @@ -0,0 +1,26 @@ + +dummysources = \ +	dummy.cc + +if HAVE_INPUT_DUMMY + +dummyltlibs = libdummy.la +dummybuildsources = $(dummysources) + +else + +dummyltlibs = +dummybuildsources = + +endif + +EXTRA_DIST = $(dummysources) + +lib_LTLIBRARIES = $(dummyltlibs) + +libdir = $(INPUT_PLUGIN_DIR) + +INCLUDES = -I$(top_srcdir)/include +libdummy_la_LDFLAGS = +libdummy_la_LIBADD = +libdummy_la_SOURCES = $(dummybuildsources) diff --git a/drumgizmo/input/dummy/dummy.cc b/drumgizmo/input/dummy/dummy.cc new file mode 100644 index 0000000..4a570db --- /dev/null +++ b/drumgizmo/input/dummy/dummy.cc @@ -0,0 +1,185 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            dummy.cc + * + *  Sat Apr 30 21:11:54 CEST 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include <stdlib.h> + +#include <string> +#include <event.h> + +class Dummy { +public: +  Dummy() {} +  ~Dummy() {} + +  bool init(int instruments, char *inames[]); + +  void setParm(std::string parm, std::string value); + +  bool start(); +  void stop(); +   +  void pre(); +  event_t *run(size_t pos, size_t len, size_t *nevents); +  void post(); +}; + +bool Dummy::init(int instruments, char *inames[]) +{ +  return true; +} + +void Dummy::setParm(std::string parm, std::string value) +{ +} + +bool Dummy::start() +{ +  return true; +} + +void Dummy::stop() +{ +} + +void Dummy::pre() +{ +} + +event_t *Dummy::run(size_t pos, size_t len, size_t *nevents) +{ +  *nevents = 0; +  return NULL; +  /* +  if(rand() % 10 != 0) return; + +  Instrument *i = NULL; +  int d = rand() % drumkit->instruments.size(); +  Instruments::iterator it = drumkit->instruments.begin(); +  while(d--) { +    i = &(it->second); +    it++; +  } + +  if(i == NULL) return; + +  Sample *s = i->sample((double)rand()/(double)RAND_MAX); +     +  if(s == NULL) { +    printf("Missing Sample.\n"); +    //    continue; +  } + +  Channels::iterator j = drumkit->channels.begin(); +  while(j != drumkit->channels.end()) { +    Channel &ch = *j; +    AudioFile *af = s->getAudioFile(&ch); +    if(af == NULL) { +      printf("Missing AudioFile.\n"); +    } else { +      printf("Adding event.\n"); +      Event *evt = new EventSample(ch.num, 1.0, af); +      eventqueue->post(evt, pos); +    } +    j++; +  } +  */ +} + +void Dummy::post() +{ +} + +extern "C" { +  void *create() +  { +    return new Dummy(); +  } +   +  void destroy(void *h) +  { +    Dummy *dummy = (Dummy*)h; +    delete dummy; +  } + +  bool init(void *h, int i, char *inames[]) +  { +    Dummy *dummy = (Dummy*)h; +    return dummy->init(i, inames); +  } + +  void setparm(void *h, const char *parm, const char *value) +  { +    Dummy *dummy = (Dummy*)h; +    dummy->setParm(parm, value); +  } + +  bool start(void *h) +  { +    Dummy *dummy = (Dummy*)h; +    return dummy->start(); +  } + +  void stop(void *h) +  { +    Dummy *dummy = (Dummy*)h; +    dummy->stop(); +  } + +  void pre(void *h) +  { +    Dummy *dummy = (Dummy*)h; +    dummy->pre(); +  } + +  event_t *run(void *h, size_t pos, size_t len, size_t *nev) +  { +    Dummy *dummy = (Dummy*)h; +    return dummy->run(pos, len, nev); +  } + +  void post(void *h) +  { +    Dummy *dummy = (Dummy*)h; +    dummy->post(); +  } +} + +#ifdef TEST_AUDIOINPUTENGINEDUMMY +//Additional dependency files +//deps: +//Required cflags (autoconf vars may be used) +//cflags: +//Required link options (autoconf vars may be used) +//libs: +#include "test.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). + +TEST_END; + +#endif/*TEST_AUDIOINPUTENGINEDUMMY*/ diff --git a/drumgizmo/input/jackmidi/Makefile.am b/drumgizmo/input/jackmidi/Makefile.am new file mode 100644 index 0000000..f357b56 --- /dev/null +++ b/drumgizmo/input/jackmidi/Makefile.am @@ -0,0 +1,28 @@ + +jackmidisources = \ +	jackmidi.cc \ +	jackclient.cc \ +	jackclient.h + +if HAVE_INPUT_JACKMIDI + +jackmidiltlibs = libjackmidi.la +jackmidibuildsources = $(jackmidisources) + +else + +jackmidiltlibs = +jackmidibuildsources = + +endif + +EXTRA_DIST = $(jackmidisources) + +lib_LTLIBRARIES = $(jackmidiltlibs) + +libdir = $(INPUT_PLUGIN_DIR) + +INCLUDES = -I$(top_srcdir)/include $(JACK_CFLAGS) +libjackmidi_la_LDFLAGS = $(JACK_LIBS) +libjackmidi_la_LIBADD = +libjackmidi_la_SOURCES = $(jackmidibuildsources) diff --git a/drumgizmo/input/jackmidi/audioinputenginejackmidi.cc b/drumgizmo/input/jackmidi/audioinputenginejackmidi.cc new file mode 100644 index 0000000..5e1fb85 --- /dev/null +++ b/drumgizmo/input/jackmidi/audioinputenginejackmidi.cc @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            audioinputenginejackmidi.cc + * + *  Sun Feb 27 11:33:31 CET 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include "audioinputenginejackmidi.h" + +#define NOTE_ON 0x90 + +AudioInputEngineJackMidi::AudioInputEngineJackMidi() +{ +  jackclient = init_jack_client(); + +  jackclient->addJackProcess(this); + +  pos = 0; +} + +AudioInputEngineJackMidi::~AudioInputEngineJackMidi() +{ +  jackclient->removeJackProcess(this); +  close_jack_client(); +} + +void AudioInputEngineJackMidi::jack_process(jack_nframes_t nframes) +{ +  void *midibuffer = jack_port_get_buffer(midi_port, nframes); + +  jack_nframes_t midievents = jack_midi_get_event_count(midibuffer); + +  for(jack_nframes_t i = 0; i < midievents; i++) { +    jack_midi_event_t event; +    jack_midi_event_get(&event, midibuffer, i); +     +    if(event.size != 3) continue; +    if((event.buffer[0] & NOTE_ON) != NOTE_ON) continue; +     +    int key = event.buffer[1]; +    int velocity = event.buffer[2]; +     +    printf("Event key:%d vel:%d\n", key, velocity); +    /* +    if(kit->midimap.find(key) == kit->midimap.end()) { +      printf("Missing note %d in midimap.\n", key); +      continue; +    } + +    std::string instr = kit->midimap[key]; + +    if(kit->instruments.find(instr) == kit->instruments.end()) { +      printf("Missing instrument %s.\n", instr.c_str()); +      continue; +    } +    */ + +    Instrument *i = NULL; +    int d = key % kit->instruments.size(); +    Instruments::iterator it = kit->instruments.begin(); +    while(d--) { +      i = &(it->second); +      it++; +    } + +    if(i == NULL) { +      continue; +    } + +    //    Sample *s = i.sample((float)velocity/127.0); +    Sample *s = i->sample(0.5); +     +    if(s == NULL) { +      printf("Missing Sample.\n"); +      continue; +    } + +    Channels::iterator j = kit->channels.begin(); +    while(j != kit->channels.end()) { +      Channel &ch = *j; +      AudioFile *af = s->getAudioFile(&ch); +      if(af == NULL) { +        printf("Missing AudioFile.\n"); +      } else { +        printf("Adding event.\n"); +        Event *evt = new EventSample(ch.num, 1.0, af); +        eventqueue->post(evt, pos + event.time + nframes); +      } +      j++; +    } +  } +   +  jack_midi_clear_buffer(midibuffer); +     +  pos += nframes; +} + +bool AudioInputEngineJackMidi::init(EventQueue *e, DrumKit *dk) +{ +  eventqueue = e; +  kit = dk; + +	midi_port = jack_port_register(jackclient->jack_client, +                                 "drumgizmo_midiin", +                                 JACK_DEFAULT_MIDI_TYPE, +                                 JackPortIsInput,// | JackPortIsTerminal, +                                 0); + +  return true; +} + + +bool AudioInputEngineJackMidi::activate() +{ +  jackclient->activate(); +  return true; +} + +#ifdef TEST_AUDIOINPUTENGINEJACKMIDI +//Additional dependency files +//deps: +//Required cflags (autoconf vars may be used) +//cflags: +//Required link options (autoconf vars may be used) +//libs: +#include "test.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). + +TEST_END; + +#endif/*TEST_AUDIOINPUTENGINEJACKMIDI*/ diff --git a/drumgizmo/input/jackmidi/audioinputenginejackmidi.h b/drumgizmo/input/jackmidi/audioinputenginejackmidi.h new file mode 100644 index 0000000..e4c6e69 --- /dev/null +++ b/drumgizmo/input/jackmidi/audioinputenginejackmidi.h @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            audioinputenginejackmidi.h + * + *  Sun Feb 27 11:33:31 CET 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#ifndef __DRUMGIZMO_AUDIOINPUTENGINEJACKMIDI_H__ +#define __DRUMGIZMO_AUDIOINPUTENGINEJACKMIDI_H__ + +#include <jack/jack.h> +#include <jack/midiport.h> + +#include "audioinputengine.h" +#include "event.h" + +#include "jackclient.h" + +class AudioInputEngineJackMidi : public AudioInputEngine, public JackProcess { +public: +  AudioInputEngineJackMidi(); +  ~AudioInputEngineJackMidi(); + +  bool init(EventQueue *e, DrumKit *drumkit); +  bool activate(); +  void run(size_t pos, size_t len) {} + +  void thread_main(); + +  void jack_process(jack_nframes_t nframes); + +private: +  DrumKit *kit; +  size_t pos; +  EventQueue *eventqueue; + +  JackClient *jackclient; +  jack_port_t *midi_port; +}; + +#endif/*__DRUMGIZMO_AUDIOINPUTENGINEJACKMIDI_H__*/ + diff --git a/drumgizmo/input/jackmidi/jackclient.cc b/drumgizmo/input/jackmidi/jackclient.cc new file mode 100644 index 0000000..4fbafb5 --- /dev/null +++ b/drumgizmo/input/jackmidi/jackclient.cc @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            jackclient.cc + * + *  Sun Jul 20 21:48:44 CEST 2008 + *  Copyright 2008 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include "jackclient.h" + +extern "C" +{ +  int _wrap_jack_process(jack_nframes_t nframes, void *arg){ +    return ((JackClient*)arg)->process(nframes);} +}  // extern "C" + +JackClient::JackClient() +  : refcnt(0) +{ +	jack_status_t status; + +	jack_client = jack_client_open("DrumGizmo", JackNullOption, &status); + +  jack_set_process_callback(jack_client, _wrap_jack_process, this); +} + +JackClient::~JackClient() +{ +	jack_client_close(jack_client); +} + +void JackClient::addJackProcess(JackProcess *process) +{ +  jack_processes.insert(process); +} + +void JackClient::removeJackProcess(JackProcess *process) +{ +  jack_processes.erase(process); +} + +void JackClient::activate() +{ +	if(!active) jack_activate(jack_client); +  active = true; +} + +int JackClient::process(jack_nframes_t nframes) +{ +  std::set<JackProcess *>::iterator i = jack_processes.begin(); +  while(i != jack_processes.end()) { +    JackProcess *jp = *i; +    jp->jack_process(nframes); +    i++; +  } + +	return 0; +} + +JackClient *jackclient = NULL; + +JackClient *init_jack_client() +{ +  if(jackclient == NULL) jackclient = new JackClient(); +  jackclient->refcnt++; +  return jackclient; + +} +void close_jack_client() +{ +  if(jackclient) { +    jackclient->refcnt--; +    if(jackclient->refcnt == 0) { +      delete jackclient; +      jackclient = NULL; +    } +  } +} diff --git a/drumgizmo/input/jackmidi/jackclient.h b/drumgizmo/input/jackmidi/jackclient.h new file mode 100644 index 0000000..88e4bbf --- /dev/null +++ b/drumgizmo/input/jackmidi/jackclient.h @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            jackclient.h + * + *  Sun Jul 20 21:48:44 CEST 2008 + *  Copyright 2008 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#ifndef __DRUMGIZMO_JACKCLIENT_H__ +#define __DRUMGIZMO_JACKCLIENT_H__ + +#include <jack/jack.h> +#include <set> + +class JackProcess { +public: +  virtual void jack_process(jack_nframes_t nframes) = 0; +}; + +class JackClient { +public: +  JackClient(); +  ~JackClient(); + +  void addJackProcess(JackProcess *process); +  void removeJackProcess(JackProcess *process); + +  void activate(); +  int process(jack_nframes_t nframes); + +	jack_client_t *jack_client; + +  // Sort of private... +  int refcnt; + +private: +  std::set<JackProcess *> jack_processes; +  bool active; +}; + +extern JackClient *jackclient; + +JackClient *init_jack_client(); +void close_jack_client(); + +#endif/*__DRUMGIZMO_JACKCLIENT_H__*/ diff --git a/drumgizmo/input/jackmidi/jackmidi.cc b/drumgizmo/input/jackmidi/jackmidi.cc new file mode 100644 index 0000000..f9faabd --- /dev/null +++ b/drumgizmo/input/jackmidi/jackmidi.cc @@ -0,0 +1,232 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            jackmidi.cc + * + *  Sat Apr 30 21:11:54 CEST 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include <stdlib.h> + +#include <event.h> +#include <string> + +#include <stdio.h> + +#define NOTE_ON 0x90 + +#include "jackclient.h" + +#include <jack/midiport.h> + +class JackMidi : public JackProcess { +public: +  JackMidi(); +  ~JackMidi(); + +  bool init(int instruments, char *inames[]); + +  void setParm(std::string parm, std::string value); + +  bool start(); +  void stop(); + +  void pre(); +  event_t *run(size_t pos, size_t len, size_t *nevents); +  void post(); + +  void jack_process(jack_nframes_t nframes); + +private: +  void loadMap(std::string map) {} + +  JackClient *jackclient; +  jack_port_t *midi_port; + +  size_t pos; + +  event_t *list; +  size_t listsize; +}; + +JackMidi::JackMidi() +{ +  jackclient = init_jack_client(); +  jackclient->addJackProcess(this); +  pos = 0; + +  list = (event_t *)malloc(sizeof(event_t) * 1000); +  listsize = 0; +} + +JackMidi::~JackMidi() +{ +  jackclient->removeJackProcess(this); +  close_jack_client(); +} + +bool JackMidi::init(int instruments, char *inames[]) +{ +	midi_port = jack_port_register(jackclient->jack_client, +                                 "drumgizmo_midiin", +                                 JACK_DEFAULT_MIDI_TYPE, +                                 JackPortIsInput,// | JackPortIsTerminal, +                                 0); + +  return true; +} + +void JackMidi::setParm(std::string parm, std::string value) +{ +  if(parm == "map") loadMap(value); +} + +bool JackMidi::start() +{ +  jackclient->activate(); +  return true; +} + +void JackMidi::stop() +{ +} + +void JackMidi::pre() +{ +} + +event_t *JackMidi::run(size_t pos, size_t len, size_t *nevents) +{ +  *nevents = listsize; +  event_t *l = list; +  list = (event_t *)malloc(sizeof(event_t) * 1000); +  listsize = 0; +  return l; +} + +void JackMidi::jack_process(jack_nframes_t nframes) +{ +  void *midibuffer = jack_port_get_buffer(midi_port, nframes); + +  jack_nframes_t midievents = jack_midi_get_event_count(midibuffer); + +  for(jack_nframes_t i = 0; i < midievents; i++) { +    jack_midi_event_t event; +    jack_midi_event_get(&event, midibuffer, i); +     +    if(event.size != 3) continue; +    if((event.buffer[0] & NOTE_ON) != NOTE_ON) continue; +     +    int key = event.buffer[1]; +    int velocity = event.buffer[2]; +     +    printf("Event key:%d vel:%d\n", key, velocity); +     +    if(velocity) { +      list[listsize].type = TYPE_ONSET; +      list[listsize].instrument = key; +      list[listsize].velocity = velocity / 127.0; +      list[listsize].offset = event.time; +      listsize++; +    } +  } +   +  jack_midi_clear_buffer(midibuffer); +     +  pos += nframes; +} + + +void JackMidi::post() +{ +} + +extern "C" { +  void *create() +  { +    return new JackMidi(); +  } +   +  void destroy(void *h) +  { +    JackMidi *jackmidi = (JackMidi*)h; +    delete jackmidi; +  } + +  bool init(void *h, int i, char *inames[]) +  { +    JackMidi *jackmidi = (JackMidi*)h; +    return jackmidi->init(i, inames); +  } + +  void setparm(void *h, const char *parm, const char *value) +  { +    JackMidi *jackmidi = (JackMidi*)h; +    jackmidi->setParm(parm, value); +  } + +  bool start(void *h) +  { +    JackMidi *jackmidi = (JackMidi*)h; +    return jackmidi->start(); +  } + +  void stop(void *h) +  { +    JackMidi *jackmidi = (JackMidi*)h; +    jackmidi->stop(); +  } + +  void pre(void *h) +  { +    JackMidi *jackmidi = (JackMidi*)h; +    jackmidi->pre(); +  } + +  event_t *run(void *h, size_t pos, size_t len, size_t *nev) +  { +    JackMidi *jackmidi = (JackMidi*)h; +    return jackmidi->run(pos, len, nev); +  } + +  void post(void *h) +  { +    JackMidi *jackmidi = (JackMidi*)h; +    jackmidi->post(); +  } +} + +#ifdef TEST_AUDIOINPUTENGINEJACKMIDI +//Additional dependency files +//deps: +//Required cflags (autoconf vars may be used) +//cflags: +//Required link options (autoconf vars may be used) +//libs: +#include "test.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). + +TEST_END; + +#endif/*TEST_AUDIOINPUTENGINEJACKMIDI*/ diff --git a/drumgizmo/input/midifile/Makefile.am b/drumgizmo/input/midifile/Makefile.am new file mode 100644 index 0000000..30a2db4 --- /dev/null +++ b/drumgizmo/input/midifile/Makefile.am @@ -0,0 +1,27 @@ + +midifilesources = \ +	midifile.cc \ +	midimap.cc + +if HAVE_INPUT_MIDIFILE + +midifileltlibs = libmidifile.la +midifilebuildsources = $(midifilesources) + +else + +midifileltlibs = +midifilebuildsources = + +endif + +EXTRA_DIST = $(midifilesources) + +lib_LTLIBRARIES = $(midifileltlibs) + +libdir = $(INPUT_PLUGIN_DIR) + +INCLUDES = -I$(top_srcdir)/include $(SMF_CFLAGS) +libmidifile_la_LDFLAGS = $(SMF_LIBS) +libmidifile_la_LIBADD = +libmidifile_la_SOURCES = $(midifilebuildsources) diff --git a/drumgizmo/input/midifile/audioinputenginemidifile.cc b/drumgizmo/input/midifile/audioinputenginemidifile.cc new file mode 100644 index 0000000..878ca1b --- /dev/null +++ b/drumgizmo/input/midifile/audioinputenginemidifile.cc @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            audioinputenginemidifile.cc + * + *  Sun Feb 27 11:43:32 CET 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include "audioinputenginemidifile.h" + +#ifdef TEST_AUDIOINPUTENGINEMIDIFILE +//Additional dependency files +//deps: +//Required cflags (autoconf vars may be used) +//cflags: +//Required link options (autoconf vars may be used) +//libs: +#include "test.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). + +TEST_END; + +#endif/*TEST_AUDIOINPUTENGINEMIDIFILE*/ diff --git a/drumgizmo/input/midifile/audioinputenginemidifile.h b/drumgizmo/input/midifile/audioinputenginemidifile.h new file mode 100644 index 0000000..6bb9ff6 --- /dev/null +++ b/drumgizmo/input/midifile/audioinputenginemidifile.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            audioinputenginemidifile.h + * + *  Sun Feb 27 11:43:32 CET 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#ifndef __DRUMGIZMO_AUDIOINPUTENGINEMIDIFILE_H__ +#define __DRUMGIZMO_AUDIOINPUTENGINEMIDIFILE_H__ + +#include "audioinputengine.h" + +class AudioInputEngineMidiFile : public AudioInputEngine { +public: +  AudioInputEngineMidiFile() {} +  ~AudioInputEngineMidiFile() {} + +  bool init(EventQueue *eventqueue, DrumKit *drumkit) { return true; } +  void run(size_t pos, size_t len) {} +}; + +#endif/*__DRUMGIZMO_AUDIOINPUTENGINEMIDIFILE_H__*/ diff --git a/drumgizmo/input/midifile/midifile.cc b/drumgizmo/input/midifile/midifile.cc new file mode 100644 index 0000000..7b17028 --- /dev/null +++ b/drumgizmo/input/midifile/midifile.cc @@ -0,0 +1,235 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            dummy.cc + * + *  Sat Apr 30 21:11:54 CEST 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include <stdlib.h> + +#include <string> +#include <event.h> + +#include <smf.h> + +#include "midimap.h" + +#define NOTE_ON 0x90 + +class MidiFile { +public: +  MidiFile(); +  ~MidiFile() {} + +  bool init(int instruments, char *inames[]); + +  void setParm(std::string parm, std::string value); + +  bool start(); +  void stop(); +   +  void pre(); +  event_t *run(size_t pos, size_t len, size_t *nevents); +  void post(); + +private: +  smf_t *smf; +  smf_event_t *cur_event; + +  MidiMap mmap; + +  // Parameters +  std::string filename; +  float speed; +  int track; +  std::string midimapfile; +}; + +MidiFile::MidiFile() +{ + cur_event = NULL; + smf = NULL; +  + filename = ""; + speed = 1.0; + track = 0; +} +  +bool MidiFile::init(int instruments, char *inames[]) +{ +  smf = smf_load(filename.c_str()); + +  mmap.load(midimapfile); + +  return true; +} + +void MidiFile::setParm(std::string parm, std::string value) +{ +  if(parm == "file") filename = value; +  if(parm == "speed") speed = atof(value.c_str()); +  if(parm == "track") track = atoi(value.c_str()); +  if(parm == "midimap") midimapfile = value; +} + +bool MidiFile::start() +{ +  return true; +} + +void MidiFile::stop() +{ +} + +void MidiFile::pre() +{ +} + +event_t *MidiFile::run(size_t pos, size_t len, size_t *nevents) +{ +  event_t *evs = NULL; +  size_t nevs = 0; + +  double cur_max_time = (double)(pos + len) / (44100.0 / speed); +  //  double cur_min_time = (double)(pos) / (44100.0 / speed); + +  if(!cur_event) cur_event = smf_get_next_event(smf); + +  while(cur_event && cur_event->time_seconds < cur_max_time) { +    if(!smf_event_is_metadata(cur_event)) { +      if( (cur_event->midi_buffer_length == 3) && +          ((cur_event->midi_buffer[0] & NOTE_ON) == NOTE_ON) && +          cur_event->track_number == track && cur_event->midi_buffer[2] > 0) { +         +        if(evs == NULL) evs = (event_t *)malloc(sizeof(event_t) * 1000); + +        int key = cur_event->midi_buffer[1]; +        int velocity = cur_event->midi_buffer[2]; + +        evs[nevs].type = TYPE_ONSET; +        size_t evpos = cur_event->time_seconds * (44100.0 / speed); +        evs[nevs].offset = evpos - pos; +        /* +        printf("evpos: %d, sec: %f, pos: %d, len: %d, max_time: %f\n", +               evpos, cur_event->time_seconds, pos, len, cur_max_time); +        */ +        evs[nevs].instrument = mmap.lookup(key); +        evs[nevs].velocity = velocity / 127.0; +         +        nevs++; +        if(nevs > 999) { +          printf("PANIC!\n"); +          break; +        } +      } +    } +     +    cur_event = smf_get_next_event(smf); +  } + +  if(!cur_event) { +    if(evs == NULL) evs = (event_t *)malloc(sizeof(event_t) * 1000); +    evs[nevs].type = TYPE_STOP; +    evs[nevs].offset = len - 1; +    nevs++; +  } + +  *nevents = nevs; + +  return evs; +} + +void MidiFile::post() +{ +} + +extern "C" { +  void *create() +  { +    return new MidiFile(); +  } +   +  void destroy(void *h) +  { +    MidiFile *midifile = (MidiFile*)h; +    delete midifile; +  } + +  bool init(void *h, int i, char *inames[]) +  { +    MidiFile *midifile = (MidiFile*)h; +    return midifile->init(i, inames); +  } + +  void setparm(void *h, const char *parm, const char *value) +  { +    MidiFile *midifile = (MidiFile*)h; +    midifile->setParm(parm, value); +  } + +  bool start(void *h) +  { +    MidiFile *midifile = (MidiFile*)h; +    return midifile->start(); +  } + +  void stop(void *h) +  { +    MidiFile *midifile = (MidiFile*)h; +    midifile->stop(); +  } + +  void pre(void *h) +  { +    MidiFile *midifile = (MidiFile*)h; +    midifile->pre(); +  } + +  event_t *run(void *h, size_t pos, size_t len, size_t *nev) +  { +    MidiFile *midifile = (MidiFile*)h; +    return midifile->run(pos, len, nev); +  } + +  void post(void *h) +  { +    MidiFile *midifile = (MidiFile*)h; +    midifile->post(); +  } +} + +#ifdef TEST_AUDIOINPUTENGINEMIDIFILE +//Additional dependency files +//deps: +//Required cflags (autoconf vars may be used) +//cflags: +//Required link options (autoconf vars may be used) +//libs: +#include "test.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). + +TEST_END; + +#endif/*TEST_AUDIOINPUTENGINEMIDIFILE*/ diff --git a/drumgizmo/input/midifile/midimap.cc b/drumgizmo/input/midifile/midimap.cc new file mode 100644 index 0000000..ccb9b3c --- /dev/null +++ b/drumgizmo/input/midifile/midimap.cc @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            midimap.cc + * + *  Mon Jun 13 21:36:30 CEST 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include "midimap.h" + +/* + +  35 = 1 +  36-51 = 2            - TODO! +  51, 53 = 3           - TODO! +  54, 56-59, 62 = 4    - TODO! + + */ + +#include <stdio.h> +#include <stdlib.h> + +MidiMap::MidiMap() +{ +} + +bool MidiMap::load(std::string file) +{ +  FILE *fp = fopen(file.c_str(), "r"); +  if(!fp) return false; + +  std::string line; +  while(!feof(fp)) { +    int c = fgetc(fp); +    //    printf("[%c]\n", c); +    if(c == '\n') { +      if(line != "") { +        int from = atoi(line.substr(0, line.find('=')).c_str()); +        int to = atoi(line.substr(line.find('=')+1, +                                  line.length()-line.find('=')+1).c_str()); +        map[from] = to; +        // printf("Line: '%s', from: %d to: %d\n", line.c_str(), from, to); +         +      } +      line = ""; +    } else { +      if((c >= '0' && c <= '9') || c == ',' || c == '-' || c == '=') { +        line += (char)c; +      } else { +        if(c != '\t' && c != ' ') return false; // Parse error. +      } +    } +  } + +  return true; +} + +int MidiMap::lookup(int note) +{ +  return map[note]; +} + +#ifdef TEST_MIDIMAP +//Additional dependency files +//deps: +//Required cflags (autoconf vars may be used) +//cflags: +//Required link options (autoconf vars may be used) +//libs: +#include "test.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). + +TEST_END; + +#endif/*TEST_MIDIMAP*/ diff --git a/drumgizmo/input/midifile/midimap.h b/drumgizmo/input/midifile/midimap.h new file mode 100644 index 0000000..183d2d3 --- /dev/null +++ b/drumgizmo/input/midifile/midimap.h @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            midimap.h + * + *  Mon Jun 13 21:36:29 CEST 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#ifndef __DRUMGIZMO_MIDIMAP_H__ +#define __DRUMGIZMO_MIDIMAP_H__ + +#include <map> +#include <string> + +class MidiMap { +public: +  MidiMap(); +  bool load(std::string file); +  int lookup(int note); + +private: +  std::map<int, int> map; +}; + +#endif/*__DRUMGIZMO_MIDIMAP_H__*/ diff --git a/drumgizmo/input/test/Makefile.am b/drumgizmo/input/test/Makefile.am new file mode 100644 index 0000000..ca45de0 --- /dev/null +++ b/drumgizmo/input/test/Makefile.am @@ -0,0 +1,26 @@ + +testsources = \ +	test.cc + +if HAVE_INPUT_TEST + +testltlibs = libtest.la +testbuildsources = $(testsources) + +else + +testltlibs = +testbuildsources = + +endif + +EXTRA_DIST = $(testsources) + +lib_LTLIBRARIES = $(testltlibs) + +libdir = $(INPUT_PLUGIN_DIR) + +INCLUDES = -I$(top_srcdir)/include +libtest_la_LDFLAGS = +libtest_la_LIBADD = +libtest_la_SOURCES = $(testbuildsources) diff --git a/drumgizmo/input/test/test.cc b/drumgizmo/input/test/test.cc new file mode 100644 index 0000000..457733f --- /dev/null +++ b/drumgizmo/input/test/test.cc @@ -0,0 +1,170 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            audioinputenginedummy.cc + * + *  Sat Apr 30 21:11:54 CEST 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include <stdlib.h> + +#include <event.h> +#include <string> + +class Test { +public: +  Test() { p = 0.1; instr = -1; } +  ~Test() {} + +  bool init(int instruments, char *inames[]); + +  void setParm(std::string parm, std::string value); + +  bool start(); +  void stop(); +   +  void pre(); +  event_t *run(size_t pos, size_t len, size_t *nevents); +  void post(); + +private: +  float p; +  int instr; +}; + +bool Test::init(int instruments, char *inames[]) +{ +  return true; +} + +void Test::setParm(std::string parm, std::string value) +{ +  if(parm == "p") p = atof(value.c_str()); +  if(parm == "instr") instr = atoi(value.c_str()); +} + +bool Test::start() +{ +  return true; +} + +void Test::stop() +{ +} + +void Test::pre() +{ +} + +event_t *Test::run(size_t pos, size_t len, size_t *nevents) +{ +  if((float)rand() / (float)RAND_MAX > p) { +    *nevents = 0; +    return NULL; +  } + +  *nevents = 1; +  event_t *evs = (event_t *)malloc(sizeof(event_t)); +  evs[0].type = TYPE_ONSET; + +  if(instr != -1) evs[0].instrument = instr; +  else evs[0].instrument = rand() % 32; + +  evs[0].velocity = (float)rand()/(float)RAND_MAX; +  evs[0].offset = len?rand()%len:0; +  return evs; +} + +void Test::post() +{ +} + +extern "C" { +  void *create() +  { +    return new Test(); +  } +   +  void destroy(void *h) +  { +    Test *test = (Test*)h; +    delete test; +  } + +  bool init(void *h, int i, char *inames[]) +  { +    Test *test = (Test*)h; +    return test->init(i, inames); +  } + +  void setparm(void *h, const char *parm, const char *value) +  { +    Test *test = (Test*)h; +    test->setParm(parm, value); +  } + +  bool start(void *h) +  { +    Test *test = (Test*)h; +    return test->start(); +  } + +  void stop(void *h) +  { +    Test *test = (Test*)h; +    test->stop(); +  } + +  void pre(void *h) +  { +    Test *test = (Test*)h; +    test->pre(); +  } + +  event_t *run(void *h, size_t pos, size_t len, size_t *nev) +  { +    Test *test = (Test*)h; +    return test->run(pos, len, nev); +  } + +  void post(void *h) +  { +    Test *test = (Test*)h; +    test->post(); +  } +} + +#ifdef TEST_AUDIOINPUTENGINETEST +//Additional dependency files +//deps: +//Required cflags (autoconf vars may be used) +//cflags: +//Required link options (autoconf vars may be used) +//libs: +#include "test.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). + +TEST_END; + +#endif/*TEST_AUDIOINPUTENGINETEST*/ diff --git a/drumgizmo/output/Makefile.am b/drumgizmo/output/Makefile.am new file mode 100644 index 0000000..14ff00b --- /dev/null +++ b/drumgizmo/output/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = @OUTPUT_PLUGINS@ diff --git a/drumgizmo/output/alsa/Makefile.am b/drumgizmo/output/alsa/Makefile.am new file mode 100644 index 0000000..d35cb21 --- /dev/null +++ b/drumgizmo/output/alsa/Makefile.am @@ -0,0 +1,26 @@ + +alsasources = \ +	alsa.cc + +if HAVE_OUTPUT_ALSA + +alsaltlibs = libalsa.la +alsabuildsources = $(alsasources) + +else + +alsaltlibs = +alsabuildsources = + +endif + +EXTRA_DIST = $(alsasources) + +lib_LTLIBRARIES = $(alsaltlibs) + +libdir = $(OUTPUT_PLUGIN_DIR) + +INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/include $(ALSA_CFLAGS) +libalsa_la_LDFLAGS = $(ALSA_LIBS) +libalsa_la_LIBADD = +libalsa_la_SOURCES = $(alsabuildsources) diff --git a/drumgizmo/output/alsa/alsa.cc b/drumgizmo/output/alsa/alsa.cc new file mode 100644 index 0000000..7b3a395 --- /dev/null +++ b/drumgizmo/output/alsa/alsa.cc @@ -0,0 +1,230 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            audiooutputenginedummy.cc + * + *  Sat Apr 30 21:12:02 CEST 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include <stdlib.h> + +#include <audiotypes.h> +#include <string> + +// Use the newer ALSA API +#define ALSA_PCM_NEW_HW_PARAMS_API + +#include <asoundlib.h> + +#define T(x, msg) if(x < 0) { printf("%s failed: %s\n", msg, snd_strerror(x)); fflush(stdout); return false; } + +#define BUFSZ 40960 + +class Alsa { +public: +  Alsa(); +  ~Alsa(); +  bool init(int channels, char *cnames[]); +  void setParm(std::string parm, std::string value); +  bool start(); +  void stop(); +  void pre(size_t size); +  void run(int channel, sample_t* data, size_t size); +  void post(size_t size); + +private: +  snd_pcm_t *handle; +  snd_pcm_hw_params_t *params; +  sample_t *data; +  size_t channels; + +  // Parameters +  std::string device; +  unsigned int srate; +  snd_pcm_uframes_t frames; +}; + +Alsa::Alsa() +{ +  handle = NULL; +  data = NULL; + +  device = "default"; +  srate = 44100; +  frames = 32; +} + +Alsa::~Alsa() +{ +  if(handle) snd_pcm_close(handle); +  if(data) free(data); +} + +bool Alsa::init(int channels, char *cnames[]) +{ +  int rc; + +  rc = snd_pcm_open(&handle, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0); +  T(rc, "snd_pcm_open"); + +  this->channels = channels; +  if(!handle) { +    printf("No handle!\n"); +    return false; +  } + +  // Allocate a hardware parameters object. +  snd_pcm_hw_params_alloca(¶ms); +  //  if(rc < 0) return false; + +  // Fill it in with default values. +  rc = snd_pcm_hw_params_any(handle, params); +  T(rc, "snd_pcm_hw_params_any"); + +  rc = snd_pcm_hw_params_set_access(handle, params, +                                    SND_PCM_ACCESS_RW_INTERLEAVED); +  T(rc, "snd_pcm_hw_params_set_access"); + +  rc = snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_FLOAT); +  T(rc, "snd_pcm_hw_params_set_format"); + +  rc = snd_pcm_hw_params_set_channels(handle, params, channels); +  T(rc, "snd_pcm_hw_params_set_channels"); + +  rc = snd_pcm_hw_params_set_rate_near(handle, params, &srate, 0); +  T(rc, "snd_pcm_hw_params_set_rate_near"); + +  rc = snd_pcm_hw_params_set_period_size_near(handle, params, &frames, 0); +  T(rc, "snd_pcm_hw_params_set_period_size_near"); +   +  rc = snd_pcm_hw_params(handle, params); +  T(rc, "snd_pcm_hw_params"); + +  data = (sample_t*)malloc(sizeof(sample_t) * BUFSZ * channels); + +  return true; +} + +void Alsa::setParm(std::string parm, std::string value) +{ +  if(parm == "dev") device = value; +  if(parm == "frames") frames = atoi(value.c_str()); +  if(parm == "srate") srate = atoi(value.c_str()); +} + +bool Alsa::start() +{ +  return true; +} + +void Alsa::stop() +{ +} + +void Alsa::pre(size_t size) +{ +} + +void Alsa::run(int channel, sample_t* cdata, size_t csize) +{ +  // Write channel data in interleaved buffer. +  for(size_t i = 0; i < csize; i++) { +    data[i * channels + channel] = cdata[i]; +  } +} + +void Alsa::post(size_t size) +{ +  // Write the interleaved buffer to the soundcard +  snd_pcm_writei(handle, data, size); +} + +extern "C" { +  void *create() +  { +    return new Alsa(); +  } +   +  void destroy(void *h) +  { +    Alsa *alsa = (Alsa*)h; +    delete alsa; +  } + +  bool init(void *h, int cs, char *cnames[]) +  { +    Alsa *alsa = (Alsa*)h; +    return alsa->init(cs, cnames); +  } + +  void setparm(void *h, const char *parm, const char *value) +  { +    Alsa *alsa = (Alsa*)h; +    alsa->setParm(parm, value); +  } + +  bool start(void *h) +  { +    Alsa *alsa = (Alsa*)h; +    return alsa->start(); +  } + +  void stop(void *h) +  { +    Alsa *alsa = (Alsa*)h; +    alsa->stop(); +  } + +  void pre(void *h, size_t s) +  { +    Alsa *alsa = (Alsa*)h; +    alsa->pre(s); +  } + +  void run(void *h, int ch, sample_t *data, size_t size) +  { +    Alsa *alsa = (Alsa*)h; +    alsa->run(ch, data, size); +  } + +  void post(void *h, size_t s) +  { +    Alsa *alsa = (Alsa*)h; +    alsa->post(s); +  } +} + +#ifdef TEST_AUDIOOUTPUTENGINEALSA +//Additional dependency files +//deps: +//Required cflags (autoconf vars may be used) +//cflags: +//Required link options (autoconf vars may be used) +//libs: +#include "test.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). + +TEST_END; + +#endif/*TEST_AUDIOOUTPUTENGINEALSA*/ diff --git a/drumgizmo/output/dummy/Makefile.am b/drumgizmo/output/dummy/Makefile.am new file mode 100644 index 0000000..ff68319 --- /dev/null +++ b/drumgizmo/output/dummy/Makefile.am @@ -0,0 +1,26 @@ + +dummysources = \ +	dummy.cc + +if HAVE_OUTPUT_DUMMY + +dummyltlibs = libdummy.la +dummybuildsources = $(dummysources) + +else + +dummyltlibs = +dummybuildsources = + +endif + +EXTRA_DIST = $(dummysources) + +lib_LTLIBRARIES = $(dummyltlibs) + +libdir = $(OUTPUT_PLUGIN_DIR) + +INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/include +libdummy_la_LDFLAGS = +libdummy_la_LIBADD = +libdummy_la_SOURCES = $(dummybuildsources) diff --git a/drumgizmo/output/dummy/dummy.cc b/drumgizmo/output/dummy/dummy.cc new file mode 100644 index 0000000..cd210dc --- /dev/null +++ b/drumgizmo/output/dummy/dummy.cc @@ -0,0 +1,156 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            audiooutputenginedummy.cc + * + *  Sat Apr 30 21:12:02 CEST 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include <stdlib.h> + +#include <audiotypes.h> +#include <string> + +class Dummy { +public: +  Dummy(); +  ~Dummy(); +  bool init(int channels, char *cnames[]); + +  void setParm(std::string parm, std::string value); + +  bool start(); +  void stop(); + +  void pre(size_t size); +  void run(int channel, sample_t* data, size_t size); +  void post(size_t size); +}; + +Dummy::Dummy() +{ +} + +Dummy::~Dummy() +{ +} + +bool Dummy::init(int channels, char *cnames[]) +{ +  return true; +} + +void Dummy::setParm(std::string parm, std::string value) +{ +} + +bool Dummy::start() +{ +  return true; +} + +void Dummy::stop() +{ +} + +void Dummy::pre(size_t size) +{ +} + +void Dummy::run(int channel, sample_t* data, size_t size) +{ +} + +void Dummy::post(size_t size) +{ +} + +extern "C" { +  void *create() +  { +    return new Dummy(); +  } +   +  void destroy(void *h) +  { +    Dummy *dummy = (Dummy*)h; +    delete dummy; +  } + +  bool init(void *h, int cs, char *cnames[]) +  { +    Dummy *dummy = (Dummy*)h; +    return dummy->init(cs, cnames); +  } + +  void setparm(void *h, const char *parm, const char *value) +  { +    Dummy *dummy = (Dummy*)h; +    dummy->setParm(parm, value); +  } + +  bool start(void *h) +  { +    Dummy *dummy = (Dummy*)h; +    return dummy->start(); +  } + +  void stop(void *h) +  { +    Dummy *dummy = (Dummy*)h; +    dummy->stop(); +  } + +  void pre(void *h, size_t size) +  { +    Dummy *dummy = (Dummy*)h; +    dummy->pre(size); +  } + +  void run(void *h, int ch, sample_t *data, size_t size) +  { +    Dummy *dummy = (Dummy*)h; +    dummy->run(ch, data, size); +  } + +  void post(void *h, size_t size) +  { +    Dummy *dummy = (Dummy*)h; +    dummy->post(size); +  } +} + +#ifdef TEST_AUDIOOUTPUTENGINEDUMMY +//Additional dependency files +//deps: +//Required cflags (autoconf vars may be used) +//cflags: +//Required link options (autoconf vars may be used) +//libs: +#include "test.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). + +TEST_END; + +#endif/*TEST_AUDIOOUTPUTENGINEDUMMY*/ diff --git a/drumgizmo/output/wavfile/Makefile.am b/drumgizmo/output/wavfile/Makefile.am new file mode 100644 index 0000000..14ffed3 --- /dev/null +++ b/drumgizmo/output/wavfile/Makefile.am @@ -0,0 +1,26 @@ + +wavfilesources = \ +	wavfile.cc + +if HAVE_OUTPUT_WAVFILE + +wavfileltlibs = libwavfile.la +wavfilebuildsources = $(wavfilesources) + +else + +wavfileltlibs = +wavfilebuildsources = + +endif + +EXTRA_DIST = $(wavfilesources) + +lib_LTLIBRARIES = $(wavfileltlibs) + +libdir = $(OUTPUT_PLUGIN_DIR) + +INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/include $(SNDFILE_CFLAGS) +libwavfile_la_LDFLAGS = $(SNDFILE_LIBS) +libwavfile_la_LIBADD = +libwavfile_la_SOURCES = $(wavfilebuildsources) diff --git a/drumgizmo/output/wavfile/wavfile.cc b/drumgizmo/output/wavfile/wavfile.cc new file mode 100644 index 0000000..03d8a7c --- /dev/null +++ b/drumgizmo/output/wavfile/wavfile.cc @@ -0,0 +1,199 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            wavfile.cc + * + *  Sat Apr 30 21:12:02 CEST 2011 + *  Copyright 2011 Bent Bisballe Nyeng + *  deva@aasimon.org + ****************************************************************************/ + +/* + *  This file is part of DrumGizmo. + * + *  DrumGizmo is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  DrumGizmo 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 General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with DrumGizmo; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include <stdlib.h> + +#include <audiotypes.h> +#include <string> + +#include <sndfile.h> + +#define T(x, msg) if(x < 0) { printf("%s failed: %s\n", msg, snd_strerror(x)); fflush(stdout); return false; } + +class WavFile { +public: +  WavFile(); +  ~WavFile(); +  bool init(int channels, char *cnames[]); +  void setParm(std::string parm, std::string value); +  bool start(); +  void stop(); +  void pre(size_t size); +  void run(int channel, sample_t* data, size_t size); +  void post(size_t size); + +private: +  SF_INFO sf_info; +  SNDFILE **fh; +  size_t channels; + +  // Parameters +  std::string filename; +}; + +WavFile::WavFile() +{ +  fh = NULL; +  filename = "output"; +} + +WavFile::~WavFile() +{ +  if(fh == NULL) return; + +  for(size_t i = 0; i < channels; i++) { +    if(fh[i]) sf_close(fh[i]); +  } + +  if(fh) free(fh); +} + +bool WavFile::init(int channels, char *cnames[]) +{ +  this->channels = channels; +   +  sf_info.channels = 1;//channels; +  sf_info.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT; +  sf_info.samplerate = 44100; + +  fh = (SNDFILE **)malloc(sizeof(SNDFILE *)*channels); + +  for(size_t i = 0; i < this->channels; i++) fh[i] = NULL; + +  for(size_t i = 0; i < this->channels; i++) { +    char fname[512]; + +    sprintf(fname, "%s%s-%d.wav", filename.c_str(), cnames[i], i); +    //    printf("[%s]\n", fname); + +    fh[i] = sf_open(fname, SFM_WRITE, &sf_info); +    if(!fh[i]) { +      printf("Write error...\n"); +      return false; +    } +  } + +  return true; +} + +void WavFile::setParm(std::string parm, std::string value) +{ +  if(parm == "file") filename = value; +} + +bool WavFile::start() +{ +  return true; +} + +void WavFile::stop() +{ +} + +void WavFile::pre(size_t size) +{ +} + +void WavFile::run(int channel, sample_t* cdata, size_t csize) +{ +  if(channel < (int)channels) sf_writef_float(fh[channel], cdata, csize);  +} + +void WavFile::post(size_t size) +{ +} + +extern "C" { +  void *create() +  { +    return new WavFile(); +  } +   +  void destroy(void *h) +  { +    WavFile *sndfile = (WavFile*)h; +    delete sndfile; +  } + +  bool init(void *h, int cs, char *cnames[]) +  { +    WavFile *sndfile = (WavFile*)h; +    return sndfile->init(cs, cnames); +  } + +  void setparm(void *h, const char *parm, const char *value) +  { +    WavFile *sndfile = (WavFile*)h; +    sndfile->setParm(parm, value); +  } + +  bool start(void *h) +  { +    WavFile *sndfile = (WavFile*)h; +    return sndfile->start(); +  } + +  void stop(void *h) +  { +    WavFile *sndfile = (WavFile*)h; +    sndfile->stop(); +  } + +  void pre(void *h, size_t s) +  { +    WavFile *sndfile = (WavFile*)h; +    sndfile->pre(s); +  } + +  void run(void *h, int ch, sample_t *data, size_t size) +  { +    WavFile *sndfile = (WavFile*)h; +    sndfile->run(ch, data, size); +  } + +  void post(void *h, size_t s) +  { +    WavFile *sndfile = (WavFile*)h; +    sndfile->post(s); +  } +} + +#ifdef TEST_AUDIOOUTPUTENGINESNDFILE +//Additional dependency files +//deps: +//Required cflags (autoconf vars may be used) +//cflags: +//Required link options (autoconf vars may be used) +//libs: +#include "test.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). + +TEST_END; + +#endif/*TEST_AUDIOOUTPUTENGINESNDFILE*/ | 
