<commit_before>// Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
#include "bstplayback.hh"
#include "bstapp.hh"




/* --- prototypes --- */
static void wave_oscillator_pcm_notify (BstPlayBackHandle *handle,
					SfiNum             tick_stamp,
					guint		   pcm_position,
					SfiProxy	   wosc);


/* --- functions --- */
BstPlayBackHandle*
bst_play_back_handle_new (void)
{
  BstPlayBackHandle *handle = new BstPlayBackHandle();

  handle->project = bse_server.create_project ("# BEAST Play Back");
  if (BST_DBG_EXT)
    gxk_idle_show_widget (GTK_WIDGET (bst_app_new (handle->project)));

  handle->snet = handle->project.create_csynth ("");
  handle->snet.auto_activate (true);
  handle->speaker = handle->snet.create_source ("BsePcmOutput");
  handle->wosc1 = Bse::WaveOscH::down_cast (handle->snet.create_source ("BseWaveOsc"));
  handle->wosc2 = Bse::WaveOscH::down_cast (handle->snet.create_source ("BseWaveOsc"));
  bse_proxy_set (handle->wosc2.proxy_id(), "channel", 2, NULL);
  handle->speaker.set_input_by_id (0, handle->wosc1, 0);
  handle->speaker.set_input_by_id (1, handle->wosc2, 0);
  handle->constant = handle->snet.create_source ("BseConstant");
  handle->wosc1.set_input_by_id (0, handle->constant, 0);
  handle->wosc2.set_input_by_id (0, handle->constant, 0);
  bse_proxy_connect (handle->wosc1.proxy_id(),
		     "swapped_signal::notify_pcm_position", wave_oscillator_pcm_notify, handle,
		     NULL);
  return handle;
}

void
bst_play_back_handle_set (BstPlayBackHandle *handle,
			  SfiProxy	     esample,
			  gdouble            osc_freq)
{
  assert_return (handle != NULL);
  if (esample)
    assert_return (BSE_IS_EDITABLE_SAMPLE (esample));

  bse_proxy_set (handle->constant.proxy_id(), "frequency_1", osc_freq, NULL);
  Bse::EditableSampleH es = Bse::EditableSampleH::down_cast (bse_server.from_proxy (esample));
  handle->wosc1.set_from_editable_sample (es);
  handle->wosc2.set_from_editable_sample (es);
}

void
bst_play_back_handle_start (BstPlayBackHandle *handle)
{
  Bse::Error error;

  error = handle->project.play();;
  if (error != 0)
    bst_status_eprintf (error, _("Playback"));
}

void
bst_play_back_handle_seek_perc (BstPlayBackHandle *handle,
				gfloat             perc)
{
  BseIt3mSeq *iseq = bse_it3m_seq_new();
  bse_it3m_seq_append (iseq, handle->wosc1.proxy_id());
  if (handle->wosc2)
    bse_it3m_seq_append (iseq, handle->wosc2.proxy_id());
  bse_wave_osc_mass_seek_perc (iseq, perc);
  if (handle->waiting_for_notify)
    handle->discard_next_notify = TRUE;
  bse_it3m_seq_free (iseq);
}<commit_msg>BST: adjust to use WaveOsc.sync_seek_perc()<commit_after>// Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
#include "bstplayback.hh"
#include "bstapp.hh"




/* --- prototypes --- */
static void wave_oscillator_pcm_notify (BstPlayBackHandle *handle,
					SfiNum             tick_stamp,
					guint		   pcm_position,
					SfiProxy	   wosc);


/* --- functions --- */
BstPlayBackHandle*
bst_play_back_handle_new (void)
{
  BstPlayBackHandle *handle = new BstPlayBackHandle();

  handle->project = bse_server.create_project ("# BEAST Play Back");
  if (BST_DBG_EXT)
    gxk_idle_show_widget (GTK_WIDGET (bst_app_new (handle->project)));

  handle->snet = handle->project.create_csynth ("");
  handle->snet.auto_activate (true);
  handle->speaker = handle->snet.create_source ("BsePcmOutput");
  handle->wosc1 = Bse::WaveOscH::down_cast (handle->snet.create_source ("BseWaveOsc"));
  handle->wosc2 = Bse::WaveOscH::down_cast (handle->snet.create_source ("BseWaveOsc"));
  bse_proxy_set (handle->wosc2.proxy_id(), "channel", 2, NULL);
  handle->speaker.set_input_by_id (0, handle->wosc1, 0);
  handle->speaker.set_input_by_id (1, handle->wosc2, 0);
  handle->constant = handle->snet.create_source ("BseConstant");
  handle->wosc1.set_input_by_id (0, handle->constant, 0);
  handle->wosc2.set_input_by_id (0, handle->constant, 0);
  bse_proxy_connect (handle->wosc1.proxy_id(),
		     "swapped_signal::notify_pcm_position", wave_oscillator_pcm_notify, handle,
		     NULL);
  return handle;
}

void
bst_play_back_handle_set (BstPlayBackHandle *handle,
			  SfiProxy	     esample,
			  gdouble            osc_freq)
{
  assert_return (handle != NULL);
  if (esample)
    assert_return (BSE_IS_EDITABLE_SAMPLE (esample));

  bse_proxy_set (handle->constant.proxy_id(), "frequency_1", osc_freq, NULL);
  Bse::EditableSampleH es = Bse::EditableSampleH::down_cast (bse_server.from_proxy (esample));
  handle->wosc1.set_from_editable_sample (es);
  handle->wosc2.set_from_editable_sample (es);
}

void
bst_play_back_handle_start (BstPlayBackHandle *handle)
{
  Bse::Error error;

  error = handle->project.play();;
  if (error != 0)
    bst_status_eprintf (error, _("Playback"));
}

void
bst_play_back_handle_seek_perc (BstPlayBackHandle *handle, float perc)
{
  Bse::WaveOscSeq woscs;
  woscs.push_back (handle->wosc1);
  if (handle->wosc2)
    woscs.push_back (handle->wosc2);
  handle->wosc1.sync_seek_perc (perc, woscs);
  if (handle->waiting_for_notify)
    handle->discard_next_notify = TRUE;
}
{'fraction_non_alphanumeric': 0.1394617953250835, 'fraction_numerical': 0.011392653702612453, 'mean_word_length': 4.6957494407158835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2097918', 'n_tokens_mistral': 2022, 'n_tokens_neox': 1929, 'n_words': 319}