Esempio n. 1
0
int
main (int argc, char *argv[]) {
  {
    static const OptionsDescriptor descriptor = {
      OPTION_TABLE(programOptions),
      .applicationName = "tunetest",
      .argumentsSummary = "{note duration} ..."
    };
    PROCESS_OPTIONS(descriptor, argc, argv);
  }

  resetPreferences();

  if (opt_tuneDevice && *opt_tuneDevice) {
    unsigned int device;

    if (!validateChoice(&device, opt_tuneDevice, deviceNames)) {
      logMessage(LOG_ERR, "%s: %s", "invalid tune device", opt_tuneDevice);
      return PROG_EXIT_SYNTAX;
    }

    prefs.tuneDevice = device;
  }

#ifdef HAVE_MIDI_SUPPORT
  if (opt_midiInstrument && *opt_midiInstrument) {
    unsigned char instrument;

    if (!validateInstrument(&instrument, opt_midiInstrument)) {
      logMessage(LOG_ERR, "%s: %s", "invalid musical instrument", opt_midiInstrument);
      return PROG_EXIT_SYNTAX;
    }

    prefs.midiInstrument = instrument;
  }
#endif /* HAVE_MIDI_SUPPORT */

  if (opt_outputVolume && *opt_outputVolume) {
    static const int minimum = 0;
    static const int maximum = 100;
    int volume;

    if (!validateInteger(&volume, opt_outputVolume, &minimum, &maximum)) {
      logMessage(LOG_ERR, "%s: %s", "invalid volume percentage", opt_outputVolume);
      return PROG_EXIT_SYNTAX;
    }

    switch (prefs.tuneDevice) {
      case tdPcm:
        prefs.pcmVolume = volume;
        break;

      case tdMidi:
        prefs.midiVolume = volume;
        break;

      case tdFm:
        prefs.fmVolume = volume;
        break;

      default:
        break;
    }
  }

  if (!argc) {
    logMessage(LOG_ERR, "missing tune.");
    return PROG_EXIT_SYNTAX;
  }

  if (argc % 2) {
    logMessage(LOG_ERR, "missing note duration.");
    return PROG_EXIT_SYNTAX;
  }

  {
    unsigned int count = argc / 2;
    TuneElement *elements = malloc((sizeof(*elements) * count) + 1);

    if (elements) {
      TuneElement *element = elements;

      while (argc) {
        int note;
        int duration;

        {
          static const int minimum = 0X01;
          static const int maximum = 0X7F;
          const char *argument = *argv++;
          if (!validateInteger(&note, argument, &minimum, &maximum)) {
            logMessage(LOG_ERR, "%s: %s", "invalid note number", argument);
            return PROG_EXIT_SYNTAX;
          }
          --argc;
        }

        {
          static const int minimum = 1;
          static const int maximum = 255;
          const char *argument = *argv++;
          if (!validateInteger(&duration, argument, &minimum, &maximum)) {
            logMessage(LOG_ERR, "%s: %s", "invalid note duration", argument);
            return PROG_EXIT_SYNTAX;
          }
          --argc;
        }

        {
          TuneElement te = TUNE_NOTE(duration, note);
          *(element++) = te;
        }
      }

      {
        TuneElement te = TUNE_STOP();
        *element = te;
      }
    } else {
      logMallocError();
      return PROG_EXIT_FATAL;
    }

    if (!setTuneDevice(prefs.tuneDevice)) {
      logMessage(LOG_ERR, "unsupported tune device: %s", deviceNames[prefs.tuneDevice]);
      return PROG_EXIT_SEMANTIC;
    }

    {
      playTune(elements);
      closeTuneDevice();
    }

    free(elements);
  }

  return PROG_EXIT_SUCCESS;
}
Esempio n. 2
0
#include <string.h>

#include "log.h"
#include "system.h"
#include "message.h"
#include "brl.h"
#include "brltty.h"
#include "prefs.h"
#include "tunes.h"
#include "notes.h"

static const TuneElement elements_braille_on[] = {
  TUNE_NOTE( 60,  64),
  TUNE_NOTE(100,  69),
  TUNE_STOP()
};
const TuneDefinition tune_braille_on = {
  NULL, 0, elements_braille_on
};

static const TuneElement elements_braille_off[] = {
  TUNE_NOTE( 60,  64),
  TUNE_NOTE( 60,  57),
  TUNE_STOP()
};
const TuneDefinition tune_braille_off = {
  NULL, 0, elements_braille_off
};

static const TuneElement elements_command_done[] = {