static Xen g_mus_set_max_table_size(Xen val)
{
  mus_long_t size;
  Xen_check_type(Xen_is_llong(val), val, 1, S_set S_mus_max_table_size, "an integer");
  size = Xen_llong_to_C_llong(val);
#if HAVE_SCHEME
  s7_symbol_set_value(s7, mus_max_table_size_symbol, s7_make_integer(s7, size));
#endif
  return(C_llong_to_Xen_llong(mus_set_max_table_size(size)));
}
Esempio n. 2
0
bool XMidiNode::applyNode(SchemeThread* st, double curtime)
{
  s7_scheme* sc=st->scheme;
  // called on Midi message nodes if an input hook is set
  int op=(mmess.getRawData()[0] & 0xf0)>>4;
  int ch=mmess.getChannel()-1;
  int d1=mmess.getRawData()[1] & 0x7f;
  int d2=0;
  if (mmess.getRawDataSize()>2)
    d2=mmess.getRawData()[2] & 0x7f;
  // convert MidiOns with zero velocity to MidiOff
  if ((op==MidiFlags::On) && (d2==0))
    op=MidiFlags::Off;
  // create list of message data
  s7_pointer args=s7_cons(sc, 
                          s7_make_integer(sc, ch),
                          s7_cons(sc,
                                  s7_make_integer(sc, d1),
                                  s7_cons(sc,
                                          s7_make_integer(sc, d2),
                                          st->schemeNil)));
  // ALWAYS PUSH OPCODE // push status opcode if default hook
  if (true) // (hook->op==0)
    args=s7_cons(sc, s7_make_integer(sc, op), args);

  // create funargs list holding data
  args=s7_cons(sc, args, st->schemeNil);
  int prot = s7_gc_protect(sc, args);
  s7_pointer res=s7_call(sc, hook->proc, args);
  s7_gc_unprotect_at(sc, prot);
  // stubbed out because a void return seems to be the same as schemeError ???????
  if (0)// (res == st->schemeError)
    {
      st->removeMidiHook(hook);
      Console::getInstance()->printError(T(">>> Removed Midi receiver.\n"));
   }
  return false;
}
void mus_sndlib_xen_initialize(void)
{
  mus_sound_initialize();
  sound_path = Xen_empty_list;

#if HAVE_RUBY
  Init_Hook();
#endif

  Xen_define_constant(S_mus_out_format,           MUS_OUT_SAMPLE_TYPE,      "sample type for fastest IO");
  Xen_define_constant(S_mus_unknown_header,       MUS_UNKNOWN_HEADER,       "unknown header type");
  Xen_define_constant(S_mus_next,                 MUS_NEXT,                 "NeXT (Sun) sound header id");
  Xen_define_constant(S_mus_aifc,                 MUS_AIFC,                 "AIFC sound header id");
  Xen_define_constant(S_mus_rf64,                 MUS_RF64,                 "RF64 sound header id");
  Xen_define_constant(S_mus_riff,                 MUS_RIFF,                 "RIFF (MS wave) sound header id");
  Xen_define_constant(S_mus_nist,                 MUS_NIST,                 "NIST (Sphere) sound header id");
  Xen_define_constant(S_mus_raw,                  MUS_RAW,                  "raw (headerless) sound header id");
  Xen_define_constant(S_mus_ircam,                MUS_IRCAM,                "IRCAM sound header id");
  Xen_define_constant(S_mus_aiff,                 MUS_AIFF,                 "AIFF (old-style) sound header id");
  Xen_define_constant(S_mus_bicsf,                MUS_BICSF,                "BICSF header id");
  Xen_define_constant(S_mus_voc,                  MUS_VOC,                  "VOC header id");
  Xen_define_constant(S_mus_svx,                  MUS_SVX,                  "SVX (IFF) header id");
  Xen_define_constant(S_mus_soundfont,            MUS_SOUNDFONT,            "soundfont header id");
  Xen_define_constant(S_mus_caff,                 MUS_CAFF,                 "Apple Core Audio File Format header id");

  Xen_define_constant(S_mus_unknown_sample,       MUS_UNKNOWN_SAMPLE,       "unknown sample type");
  Xen_define_constant(S_mus_bshort,               MUS_BSHORT,               "big-endian short sample type id");
  Xen_define_constant(S_mus_lshort,               MUS_LSHORT,               "little-endian short sample type id");
  Xen_define_constant(S_mus_mulaw,                MUS_MULAW,                "mulaw (8-bit) sample type id");
  Xen_define_constant(S_mus_alaw,                 MUS_ALAW,                 "alaw (8-bit) sample type id");
  Xen_define_constant(S_mus_byte,                 MUS_BYTE,                 "signed byte sample type id");
  Xen_define_constant(S_mus_ubyte,                MUS_UBYTE,                "unsigned byte sample type id");
  Xen_define_constant(S_mus_bfloat,               MUS_BFLOAT,               "big-endian float sample type id");
  Xen_define_constant(S_mus_lfloat,               MUS_LFLOAT,               "little-endian float sample type id");
  Xen_define_constant(S_mus_bint,                 MUS_BINT,                 "big-endian int sample type id");
  Xen_define_constant(S_mus_lint,                 MUS_LINT,                 "little-endian int sample type id");
  Xen_define_constant(S_mus_bintn,                MUS_BINTN,                "normalized big-endian int sample type id");
  Xen_define_constant(S_mus_lintn,                MUS_LINTN,                "normalized little-endian int sample type id");
  Xen_define_constant(S_mus_b24int,               MUS_B24INT,               "big-endian 24-bit sample type id");
  Xen_define_constant(S_mus_l24int,               MUS_L24INT,               "little-endian 24-bit sample type id");
  Xen_define_constant(S_mus_bdouble,              MUS_BDOUBLE,              "big-endian double sample type id");
  Xen_define_constant(S_mus_ldouble,              MUS_LDOUBLE,              "little-endian double sample type id");
  Xen_define_constant(S_mus_ubshort,              MUS_UBSHORT,              "unsigned big-endian short sample type id");
  Xen_define_constant(S_mus_ulshort,              MUS_ULSHORT,              "unsigned little-endian short sample type id");
  Xen_define_constant(S_mus_bdouble_unscaled,     MUS_BDOUBLE_UNSCALED,     "unscaled big-endian double sample type id");
  Xen_define_constant(S_mus_ldouble_unscaled,     MUS_LDOUBLE_UNSCALED,     "unscaled little-endian double sample type id");
  Xen_define_constant(S_mus_bfloat_unscaled,      MUS_BFLOAT_UNSCALED,      "unscaled big-endian float sample type id");
  Xen_define_constant(S_mus_lfloat_unscaled,      MUS_LFLOAT_UNSCALED,      "unscaled little-endian float sample type id");

  Xen_define_dilambda(S_mus_sound_samples, g_mus_sound_samples_w, H_mus_sound_samples,  S_set S_mus_sound_samples, g_mus_sound_set_samples_w, 1, 0, 2, 0);
  Xen_define_dilambda(S_mus_sound_data_location, g_mus_sound_data_location_w, H_mus_sound_data_location,
		      S_set S_mus_sound_data_location, g_mus_sound_set_data_location_w, 1, 0, 2, 0);
  Xen_define_dilambda(S_mus_sound_chans, g_mus_sound_chans_w, H_mus_sound_chans, S_set S_mus_sound_chans, g_mus_sound_set_chans_w, 1, 0, 2, 0);
  Xen_define_dilambda(S_mus_sound_srate, g_mus_sound_srate_w, H_mus_sound_srate, S_set S_mus_sound_srate, g_mus_sound_set_srate_w, 1, 0, 2, 0);
  Xen_define_dilambda(S_mus_sound_header_type, g_mus_sound_header_type_w, H_mus_sound_header_type,
		      S_set S_mus_sound_header_type, g_mus_sound_set_header_type_w, 1, 0, 2, 0);
  Xen_define_dilambda(S_mus_sound_sample_type, g_mus_sound_sample_type_w, H_mus_sound_sample_type,
		      S_set S_mus_sound_sample_type, g_mus_sound_set_sample_type_w, 1, 0, 2, 0);


  /* -------------------------------------------------------------------------------- */

  Xen_define_safe_procedure(S_mus_sound_framples,       g_mus_sound_framples_w,         1, 0, 0, H_mus_sound_framples);
  Xen_define_safe_procedure("mus-sound-frames",         g_mus_sound_framples_w,         1, 0, 0, H_mus_sound_framples);
  Xen_define_safe_procedure(S_mus_sound_duration,       g_mus_sound_duration_w,         1, 0, 0, H_mus_sound_duration);
  Xen_define_safe_procedure(S_mus_sound_datum_size,     g_mus_sound_datum_size_w,       1, 0, 0, H_mus_sound_datum_size);
  Xen_define_safe_procedure(S_mus_sound_length,         g_mus_sound_length_w,           1, 0, 0, H_mus_sound_length);
  Xen_define_safe_procedure(S_mus_sound_type_specifier, g_mus_sound_type_specifier_w,   1, 0, 0, H_mus_sound_type_specifier);
  Xen_define_safe_procedure(S_mus_header_type_name,     g_mus_header_type_name_w,       1, 0, 0, H_mus_header_type_name);
  Xen_define_safe_procedure(S_mus_header_type_to_string,g_mus_header_type_to_string_w,  1, 0, 0, H_mus_header_type_to_string);
  Xen_define_safe_procedure(S_mus_header_writable,      g_mus_header_writable_w,        2, 0, 0, H_mus_header_writable);
  Xen_define_safe_procedure(S_mus_sample_type_name,     g_mus_sample_type_name_w,       1, 0, 0, H_mus_sample_type_name);
  Xen_define_safe_procedure(S_mus_sample_type_to_string,g_mus_sample_type_to_string_w,  1, 0, 0, H_mus_sample_type_to_string);
#if HAVE_SCHEME
  Xen_define_dilambda(S_mus_sound_sample_type, g_mus_sound_sample_type_w, H_mus_sound_sample_type,
		      S_set S_mus_sound_sample_type, g_mus_sound_set_sample_type_w, 1, 0, 2, 0);
#endif
  Xen_define_safe_procedure(S_mus_sound_comment,        g_mus_sound_comment_w,          1, 0, 0, H_mus_sound_comment);
  Xen_define_safe_procedure(S_mus_sound_write_date,     g_mus_sound_write_date_w,       1, 0, 0, H_mus_sound_write_date);
  Xen_define_safe_procedure(S_mus_bytes_per_sample,     g_mus_bytes_per_sample_w,       1, 0, 0, H_mus_bytes_per_sample);
  Xen_define_safe_procedure(S_mus_sound_loop_info,      g_mus_sound_loop_info_w,        1, 0, 0, H_mus_sound_loop_info);
  Xen_define_safe_procedure(S_mus_sound_mark_info,      g_mus_sound_mark_info_w,        1, 0, 0, H_mus_sound_mark_info);
  Xen_define_safe_procedure(S_mus_sound_maxamp_exists,  g_mus_sound_maxamp_exists_w,    1, 0, 0, H_mus_sound_maxamp_exists);
  Xen_define_safe_procedure(S_mus_sound_forget,         g_mus_sound_forget_w,           1, 0, 0, H_mus_sound_forget);
  Xen_define_safe_procedure(S_mus_sound_prune,          g_mus_sound_prune_w,            0, 0, 0, H_mus_sound_prune);

  Xen_define_safe_procedure(S_mus_expand_filename,      g_mus_expand_filename_w,        1, 0, 0, H_mus_expand_filename);
  Xen_define_safe_procedure(S_mus_sound_report_cache,   g_mus_sound_report_cache_w,     0, 1, 0, H_mus_sound_report_cache);
  Xen_define_safe_procedure(S_mus_error_type_to_string, g_mus_error_type_to_string_w,   1, 0, 0, H_mus_error_type_to_string);
  Xen_define_safe_procedure(S_mus_oss_set_buffers,      g_mus_oss_set_buffers_w,        2, 0, 0, H_mus_oss_set_buffers);
  Xen_define_safe_procedure(S_array_to_file,            g_array_to_file_w,              5, 0, 0, H_array_to_file);
  Xen_define_safe_procedure(S_file_to_array,            g_file_to_array_w,              5, 0, 0, H_file_to_array);

  Xen_define_safe_procedure(S_mus_sound_preload,        g_mus_sound_preload_w,          1, 0, 0, H_mus_sound_preload);

  Xen_define_dilambda(S_mus_header_raw_defaults, g_mus_header_raw_defaults_w, H_mus_header_raw_defaults,
		      S_set S_mus_header_raw_defaults, g_mus_header_set_raw_defaults_w, 0, 0, 1, 0);

  Xen_define_dilambda(S_mus_clipping, g_mus_clipping_w, H_mus_clipping, S_set S_mus_clipping, g_mus_set_clipping_w, 0, 0, 1, 0);
  Xen_define_dilambda(S_mus_file_clipping, g_mus_file_clipping_w, H_mus_file_clipping, S_set S_mus_file_clipping, g_mus_file_set_clipping_w, 1, 0, 2, 0);
  Xen_define_dilambda(S_mus_sound_maxamp, g_mus_sound_maxamp_w, H_mus_sound_maxamp, S_set S_mus_sound_maxamp, g_mus_sound_set_maxamp_w, 1, 0, 2, 0);

  /* these are no-ops if not ALSA, but that makes it easier to maintain global initialization files */
  Xen_define_dilambda(S_mus_alsa_buffers, g_mus_alsa_buffers_w, H_mus_alsa_buffers, S_set S_mus_alsa_buffers, g_mus_alsa_set_buffers_w, 0, 0, 1, 0);
  Xen_define_dilambda(S_mus_alsa_buffer_size, g_mus_alsa_buffer_size_w, H_mus_alsa_buffer_size, S_set S_mus_alsa_buffer_size, g_mus_alsa_set_buffer_size_w, 0, 0, 1, 0);
  Xen_define_dilambda(S_mus_alsa_device, g_mus_alsa_device_w, H_mus_alsa_device, S_set S_mus_alsa_device, g_mus_alsa_set_device_w, 0, 0, 1, 0);

  Xen_define_dilambda(S_mus_alsa_playback_device, g_mus_alsa_playback_device_w, H_mus_alsa_playback_device, 
		      S_set S_mus_alsa_playback_device, g_mus_alsa_set_playback_device_w, 0, 0, 1, 0);
  Xen_define_dilambda(S_mus_alsa_capture_device, g_mus_alsa_capture_device_w, H_mus_alsa_capture_device, 
		      S_set S_mus_alsa_capture_device, g_mus_alsa_set_capture_device_w, 0, 0, 1, 0);
  Xen_define_dilambda(S_mus_alsa_squelch_warning, g_mus_alsa_squelch_warning_w, H_mus_alsa_squelch_warning,
		      S_set S_mus_alsa_squelch_warning, g_mus_alsa_set_squelch_warning_w, 0, 0, 1, 0);

  Xen_define_dilambda(S_mus_max_malloc, g_mus_max_malloc_w, H_mus_max_malloc, S_set S_mus_max_malloc, g_mus_set_max_malloc_w, 0, 0, 1, 0);
  Xen_define_dilambda(S_mus_max_table_size, g_mus_max_table_size_w, H_mus_max_table_size, S_set S_mus_max_table_size, g_mus_set_max_table_size_w, 0, 0, 1, 0);
  Xen_define_dilambda(S_mus_sound_path, g_mus_sound_path_w, H_mus_sound_path, S_set S_mus_sound_path, g_mus_set_sound_path_w, 0, 0, 1, 0);

#if HAVE_SCHEME
  mus_max_table_size_symbol = s7_define_variable(s7, "*" S_mus_max_table_size "*", s7_make_integer(s7, MUS_MAX_TABLE_SIZE_DEFAULT));
  s7_symbol_set_documentation(s7, mus_max_table_size_symbol, "*mus-max-table-size*: maximum table size.");
  s7_symbol_set_access(s7, mus_max_table_size_symbol, s7_make_function(s7, "[acc-mus-max-table-size]", acc_mus_max_table_size, 2, 0, false, "accessor"));

  mus_max_malloc_symbol = s7_define_variable(s7, "*" S_mus_max_malloc "*", s7_make_integer(s7, MUS_MAX_MALLOC_DEFAULT));
  s7_symbol_set_documentation(s7, mus_max_malloc_symbol, "*mus-max-malloc*: maximum number of bytes we will try to malloc.");
  s7_symbol_set_access(s7, mus_max_malloc_symbol, s7_make_function(s7, "[acc-mus-max-malloc]", acc_mus_max_malloc, 2, 0, false, "accessor"));

  mus_sound_path_symbol = s7_define_variable(s7, "*" S_mus_sound_path "*", s7_nil(s7));
  s7_symbol_set_documentation(s7, mus_sound_path_symbol, "*" S_mus_sound_path "* is a list of directories to search for sound files");
  s7_symbol_set_access(s7, mus_sound_path_symbol, s7_make_function(s7, "[acc-mus-sound-path]", acc_mus_sound_path, 2, 0, false, "accessor"));
#endif

#if __APPLE__
  Xen_define_procedure(S_mus_audio_output_properties_mutable, g_mus_audio_output_properties_mutable_w, 1, 0, 0, H_mus_audio_output_properties_mutable);
#endif

  #define H_new_sound_hook S_new_sound_hook "(name): called when a new sound file is being created"
  new_sound_hook = Xen_define_hook(S_new_sound_hook, "(make-hook 'name)", 1, H_new_sound_hook);
  mus_header_write_set_hook(g_new_sound_hook);

  Xen_provide_feature("sndlib");
}
Esempio n. 4
0
bool XOscNode::applyNode(SchemeThread* st, double curtime)
{
  //std::cout << "Osc message: "<< path.toUTF8() << " " << types.toUTF8();
  ////st->lockOscHook();
  //std::cout << "Osc hook!\n";
  s7_scheme* sc=st->scheme;
  // the osc message data starts with the string path
  s7_pointer snil = st->schemeNil;
  s7_pointer data = s7_cons(sc, st->schemeFalse, snil) ; // (#f) placeholder
  s7_pointer tail = data;
  
  // iterate types adding floats and ints to message data
  int F=0;
  int I=0;
  int S=0;
  for (int i=0; i<types.length(); i++)
    {
      switch (types[i])
        {
        case 'i':  // LO_INT32
        case 'h':  // LO_INT64
          s7_set_cdr(tail, s7_cons(sc, s7_make_integer(sc, ints[I++]), snil));
          break;
        case 'f':  // LO_FLOAT32
        case 'd':  // LO_FLOAT64
        case 't':  // LO_TIMETAG
          s7_set_cdr(tail, s7_cons(sc, s7_make_real(sc, flos[F++]), snil));
          break;
        case 's':  // LO_STRING
          s7_set_cdr(tail, s7_cons(sc, s7_make_string(sc, strs[S++].toUTF8()), snil));
          break;
        case 'S':  // LO_SYMBOL
          s7_set_cdr(tail, s7_cons(sc, s7_make_symbol(sc, strs[S++].toUTF8()), snil));
          break;
        case 'T':  // LO_TRUE
          s7_set_cdr(tail, s7_cons(sc, s7_make_boolean(sc, true), snil));
          break;
        case 'F':  // LO_FALSE
          s7_set_cdr(tail, s7_cons(sc, s7_make_boolean(sc, false), snil));
          break;
        case 'N':  // LO_NIL
          s7_set_cdr(tail, s7_cons(sc, snil, snil));
          break;
        case 'I':  // LO_INFINITUM
          s7_set_cdr(tail, s7_cons(sc, s7_name_to_value(sc, "most-positive-fixnum"), snil));
          break;
        case 'c':  // LO_CHAR
          s7_set_cdr(tail, s7_cons(sc, s7_make_character(sc, (char)ints[I++]), snil));
          break;
        case 'm':  // LO_MIDI
          {
            s7_pointer m=s7_cons(sc, s7_make_integer(sc, ints[I+0]),
                                 s7_cons(sc, s7_make_integer(sc, ints[I+1]),
                                         s7_cons(sc, s7_make_integer(sc, ints[I+2]),
                                                 s7_cons(sc, s7_make_integer(sc, ints[I+3]), snil))));
            s7_set_cdr(tail, s7_cons(sc, s7_cons(sc, m, snil), snil));
            I+=4;
          }
          break;
        case 'b':  // LO_BLOB
          {
            int l=(int)ints[I++]; // length of blob
            s7_pointer m=snil;
            for (int j=I+l-1; i>=I; j--)
              m=s7_cons(sc, s7_make_integer(sc, ints[j]), m);
            s7_set_cdr(tail, s7_cons(sc, s7_cons(sc, m, snil), snil));
            I+=l;
          }
          break;
        default:
          break;
        }
      tail=s7_cdr(tail);
    }
  // data is now (#f x y ...) 
  int loc;
  s7_pointer args, res;
  if (hook->path==String::empty) // is default hook
    {
      // default hook includes path as first element
      // replace placeholder #f with path
      s7_set_car(data, s7_make_string(sc, path.toUTF8()));
      args=s7_cons(sc, data, snil);
      // args now ((x y ...))
      loc = s7_gc_protect(sc, args);
      res = s7_call(sc, hook->proc, args);
    }
  else
    {
      //      // no path so reuse placeholder's cons cell:
      //      s7_set_car(data, s7_cdr(data)); 
      //      // data now ((x y ...) x y ...)
      //      s7_set_cdr(data, snil); 
      //      // data now ((x y ...))
      //      loc = s7_gc_protect(sc, data);
      //      res=s7_call(sc, hook->proc, data);
      s7_set_car(data, s7_make_string(sc, hook->path.toUTF8()));
      args=s7_cons(sc, data, snil);
      loc = s7_gc_protect(sc, args);
      res = s7_call(sc, hook->proc, args);
    }
  s7_gc_unprotect_at(sc, loc);
  // stubbed out because a void return seems to be the same as schemeError ???????
  if (0) // (res == st->schemeError)
    {
      st->removeOscHook(hook);
      Console::getInstance()->printError(T(">>> Removed OSC receiver.\n"));
    }
  return false;
}