<commit_before>/*
 * BRLTTY - A background process providing access to the console screen (when in
 *          text mode) for a blind person using a refreshable braille display.
 *
 * Copyright (C) 1995-2007 by The BRLTTY Developers.
 *
 * BRLTTY comes with ABSOLUTELY NO WARRANTY.
 *
 * This is free software, placed under the terms of the
 * GNU General Public License, as published by the Free Software
 * Foundation.  Please see the file COPYING for details.
 *
 * Web Page: http://mielke.cc/brltty/
 *
 * This software is maintained by <NAME> <<EMAIL>>.
 */

#include "prologue.h"

#include "misc.h"
#include "system.h"
#include "notes.h"

static int beeperOpened = 0;

static int beeperConstruct (int errorLevel) {
   if (!beeperOpened) {
      if (!canBeep()) {
         LogPrint(LOG_DEBUG, "cannot open beeper.");
         return 0;
      }
      beeperOpened = 1;
      LogPrint(LOG_DEBUG, "beeper opened.");
   }
   return 1;
}

static int beeperPlay (int note, int duration) {
   if (beeperOpened) {
      LogPrint(LOG_DEBUG, "tone: msec=%d note=%d",
               duration, note);

      if (!note) {
         accurateDelay(duration);
	 return 1;
      }

      if (asynchronousBeep((int)noteFrequencies[note], duration*4)) {
         accurateDelay(duration);
	 stopBeep();
         return 1;
      }

      if (startBeep((int)noteFrequencies[note])) {
         accurateDelay(duration);
	 stopBeep();
         return 1;
      }

      if (synchronousBeep((int)noteFrequencies[note], duration)) return 1;
   }
   return 0;
}

static int beeperFlush (void) {
   return beeperOpened;
}

static void beeperDestruct (void) {
   if (beeperOpened) {
      beeperOpened = 0;
      endBeep();
      LogPrint(LOG_DEBUG, "beeper closed.");
   }
}

const NoteGenerator beeperNoteGenerator = {
   beeperConstruct,
   beeperPlay,
   beeperFlush,
   beeperDestruct
};<commit_msg>Standardize the beeper source code. (dm)<commit_after>/*
 * BRLTTY - A background process providing access to the console screen (when in
 *          text mode) for a blind person using a refreshable braille display.
 *
 * Copyright (C) 1995-2007 by The BRLTTY Developers.
 *
 * BRLTTY comes with ABSOLUTELY NO WARRANTY.
 *
 * This is free software, placed under the terms of the
 * GNU General Public License, as published by the Free Software
 * Foundation.  Please see the file COPYING for details.
 *
 * Web Page: http://mielke.cc/brltty/
 *
 * This software is maintained by <NAME> <<EMAIL>>.
 */

#include "prologue.h"

#include "misc.h"
#include "system.h"
#include "notes.h"

static int beeperEnabled = 0;

static int
beeperConstruct (int errorLevel) {
  if (!beeperEnabled) {
    if (!canBeep()) {
      LogPrint(LOG_DEBUG, "beeper not available");
      return 0;
    }

    beeperEnabled = 1;
    LogPrint(LOG_DEBUG, "beeper enabled");
  }

  return 1;
}

static int
beeperPlay (int note, int duration) {
  if (beeperEnabled) {
    LogPrint(LOG_DEBUG, "tone: msec=%d note=%d",
             duration, note);

    if (!note) {
      accurateDelay(duration);
      return 1;
    }

    if (asynchronousBeep((int)noteFrequencies[note], duration*4)) {
      accurateDelay(duration);
      stopBeep();
      return 1;
    }

    if (startBeep((int)noteFrequencies[note])) {
      accurateDelay(duration);
      stopBeep();
      return 1;
    }

    if (synchronousBeep((int)noteFrequencies[note], duration)) return 1;
  }

  return 0;
}

static int
beeperFlush (void) {
  return beeperEnabled;
}

static void
beeperDestruct (void) {
  if (beeperEnabled) {
    beeperEnabled = 0;
    endBeep();
    LogPrint(LOG_DEBUG, "beeper disabled");
  }
}

const NoteGenerator beeperNoteGenerator = {
  beeperConstruct,
  beeperPlay,
  beeperFlush,
  beeperDestruct
};
{'fraction_non_alphanumeric': 0.1123294998662744, 'fraction_numerical': 0.010163145225996255, 'mean_word_length': 3.0171858216970997, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5170122', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1219, 'n_words': 354}