def _toggle_metronome(self): s = settings.get() s.recording_metronome_enabled = not s.recording_metronome_enabled if s.recording_metronome_enabled: samples_per_beat = song_timing.get_samples_per_beat( self._project.sample_rate, self._project.beats_per_minute) engine.set_metronome_samples_per_beat(samples_per_beat) else: engine.set_metronome_samples_per_beat(0.0) self._metronome_button.icon_name = self._get_metronome_icon()
def _on_time_bar_sample_changed(self): sample_index = self._timeline.get_playback_sample_index() self._last_clicked_sample_index = sample_index if self._is_playing: s = settings.get() assert s.output_device_index is not None # Should not have changed # Stopping and starting the stream at the new position should be good enough engine.stop_playback() engine.start_playback(s.output_device_index, s.frames_per_buffer, int(sample_index))
def _play_pause(self): if not self._is_playing: engine_clip = self._engine_clip if engine_clip is None: assert self._clip is not None engine_clip = self._clip.engine_clip assert engine_clip is not None s = settings.get() if s.output_device_index is None: modal_dialog.show_simple_modal_dialog( self._stack_widget, "Output device not set", "The output device must be set before playback.", ["OK"], None) return start_sample_index = self._waveform_viewer.start_sample_index end_sample_index = self._waveform_viewer.end_sample_index gain = self._gain_spinner.value engine.playback_builder_begin() engine.playback_builder_add_clip(engine_clip, start_sample_index, end_sample_index, start_sample_index, gain) engine.playback_builder_finalize() if s.recording_metronome_enabled: samples_per_beat = song_timing.get_samples_per_beat( self._project.sample_rate, self._project.beats_per_minute) engine.set_metronome_samples_per_beat(samples_per_beat) else: engine.set_metronome_samples_per_beat(0.0) engine.start_playback(s.output_device_index, s.frames_per_buffer, int(self._time_bar.sample)) self._is_playing = True self._playback_updater = timer.Updater(self._playback_update) self._record_button.set_enabled(False) self._play_pause_button.icon_name = "pause" else: engine.stop_playback() self._is_playing = False self._playback_updater.cancel() self._playback_updater = None self._record_button.set_enabled(True) self._play_pause_button.icon_name = "play"
def _accept(self): s = settings.get() s.input_device_index = self._input_device.selected_option_index s.output_device_index = self._output_device.selected_option_index self._destroy_func()
def __init__(self, stack_widget): self._stack_widget = stack_widget layout = widget.VStackedLayoutWidget() title = widget.TextWidget() title.text = "Settings" title.size.value = points(20.0) title.horizontal_alignment = drawing.HorizontalAlignment.CENTER title.vertical_alignment = drawing.VerticalAlignment.MIDDLE layout.add_child(title) layout.add_padding(points(12.0)) options_layout = widget.GridLayoutWidget() layout.add_child(options_layout) options_layout.set_column_size(1, points(4.0)) input_device_title = widget.TextWidget() options_layout.add_child( 0, 0, input_device_title, horizontal_placement=widget.HorizontalPlacement.RIGHT) input_device_title.text = "Input device:" input_device_title.horizontal_alignment = drawing.HorizontalAlignment.RIGHT input_device_title.vertical_alignment = drawing.VerticalAlignment.MIDDLE input_device_count = engine.get_input_device_count() self._input_device = widget.DropdownWidget() options_layout.add_child(0, 2, self._input_device) self._input_device.set_options([(i, engine.get_input_device_name(i)) for i in range(input_device_count)]) self._input_device.selected_option_index = settings.get( ).input_device_index options_layout.set_row_size(1, points(12.0)) output_device_title = widget.TextWidget() options_layout.add_child( 2, 0, output_device_title, horizontal_placement=widget.HorizontalPlacement.RIGHT) output_device_title.text = "Output device:" output_device_title.horizontal_alignment = drawing.HorizontalAlignment.RIGHT output_device_title.vertical_alignment = drawing.VerticalAlignment.MIDDLE output_device_count = engine.get_output_device_count() self._output_device = widget.DropdownWidget() options_layout.add_child(2, 2, self._output_device) self._output_device.set_options([(i, engine.get_output_device_name(i)) for i in range(output_device_count)]) self._output_device.selected_option_index = settings.get( ).output_device_index layout.add_padding(points(12.0)) buttons_layout = widget.HStackedLayoutWidget() layout.add_child(buttons_layout) buttons_layout.add_padding(0.0, weight=1.0) cancel_button = widget.TextButtonWidget() buttons_layout.add_child(cancel_button) cancel_button.text = "Cancel" cancel_button.action_func = self._cancel buttons_layout.add_padding(points(4.0)) ok_button = widget.TextButtonWidget() buttons_layout.add_child(ok_button) ok_button.text = "OK" ok_button.action_func = self._accept self._destroy_func = modal_dialog.show_modal_dialog( stack_widget, layout)
def _get_metronome_icon(self): return "metronome" if settings.get( ).playback_metronome_enabled else "metronome_disabled"
def _play_pause(self): if not self._is_playing: s = settings.get() if s.output_device_index is None: modal_dialog.show_simple_modal_dialog( self._root_stack_widget, "Output device not set", "The output device must be set before playback.", ["OK"], None) return soloed_tracks = set(x for x in self._project.tracks if x.soloed and not x.muted) if len(soloed_tracks) > 0: active_tracks = [ x for x in self._project.tracks if x in soloed_tracks ] else: active_tracks = [ x for x in self._project.tracks if not x.muted ] # Build the playback clip engine.playback_builder_begin() samples_per_measure = song_timing.get_samples_per_measure( self._project.sample_rate, self._project.beats_per_minute, self._project.beats_per_measure) for track in active_tracks: for i, clip_id in enumerate(track.measure_clip_ids): if clip_id is not None: clip = self._project.get_clip_by_id(clip_id) measure_index = i if clip.has_intro: measure_index -= 1 playback_start_sample_index = round( measure_index * samples_per_measure + clip.start_sample_index) gain = clip.gain * clip.category.gain * track.gain engine.playback_builder_add_clip( clip.engine_clip, clip.start_sample_index, clip.end_sample_index, playback_start_sample_index, gain) engine.playback_builder_finalize() if s.playback_metronome_enabled: samples_per_beat = song_timing.get_samples_per_beat( self._project.sample_rate, self._project.beats_per_minute) engine.set_metronome_samples_per_beat(samples_per_beat) else: engine.set_metronome_samples_per_beat(0.0) engine.start_playback( s.output_device_index, s.frames_per_buffer, int(self._timeline.get_playback_sample_index())) self._is_playing = True self._playback_updater = timer.Updater(self._playback_update) self._project_widgets.play_pause_button.icon_name = "pause" self._update_controls_enabled() else: engine.stop_playback() self._is_playing = False self._playback_updater.cancel() self._playback_updater = None self._project_widgets.play_pause_button.icon_name = "play" self._update_controls_enabled()
def _get_metronome_icon(self): return "metronome" if settings.get( ).recording_metronome_enabled else "metronome_disabled"
def _record(self): if not self._is_recording: s = settings.get() if s.input_device_index is None: modal_dialog.show_simple_modal_dialog( self._stack_widget, "Input device not set", "The input device must be set before recording.", ["OK"], None) return if s.output_device_index is None: modal_dialog.show_simple_modal_dialog( self._stack_widget, "Output device not set", "The output device must be set before recording.", ["OK"], None) return if self._engine_clip is not None: engine.delete_clip(self._engine_clip) if s.recording_metronome_enabled: samples_per_beat = song_timing.get_samples_per_beat( self._project.sample_rate, self._project.beats_per_minute) engine.set_metronome_samples_per_beat(samples_per_beat) else: engine.set_metronome_samples_per_beat(0.0) self._engine_clip = engine.start_recording_clip( s.input_device_index, s.output_device_index, s.frames_per_buffer) self._is_recording = True self._recording_updater = timer.Updater(self._recording_update) self._record_button.icon_name = "stop" self._play_pause_button.set_enabled(False) self._stop_button.set_enabled(False) self._accept_button.set_enabled(False) self._reject_button.set_enabled(False) self._intro_checkbox.set_enabled(False) self._outro_checkbox.set_enabled(False) self._gain_spinner.set_enabled(False) self._update_time_bar() self._waveform_viewer.enabled = False self._update_measures_text() else: engine.stop_recording_clip() self._is_recording = False self._recording_updater.cancel() self._recording_updater = None self._record_button.icon_name = "record" self._play_pause_button.set_enabled(True) self._stop_button.set_enabled(True) self._accept_button.set_enabled(True) self._reject_button.set_enabled(True) self._intro_checkbox.set_enabled(True) self._outro_checkbox.set_enabled(True) self._gain_spinner.set_enabled(True) self._update_time_bar() self._waveform_viewer.set_waveform_samples( engine.get_clip_samples(self._engine_clip, _MAX_WAVEFORM_SAMPLES)) self._waveform_viewer.sample_count = engine.get_clip_sample_count( self._engine_clip) self._waveform_viewer.start_sample_index = 0 self._waveform_viewer.end_sample_index = self._waveform_viewer.sample_count self._waveform_viewer.enabled = True self._update_measures_text()