Skip to content

Commit

Permalink
Rename Lane -> Track
Browse files Browse the repository at this point in the history
Previously have chosen a different name to not have name conflicts with
midly, but "Lane" seems confusing as we do not support multi-track
compositions, or one may think that "lane" refers to e.g. a pitch on the
stave.

Will have midly types always prefixed with `midly::` from now on.
  • Loading branch information
PetrGlad committed Oct 19, 2023
1 parent 2e08318 commit 05f9445
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 117 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Big scary problems
VST3 is GPL. LV2 seem like a decent choice. Here seem to be an LV2 host implementation in
Rust https://github.com/wmedrano/livi-rs. Can also implement one from scratch, or use JACK API and register emmate as
a MIDI sequencer. Pipewire seems to SUPPORT JACK API as well (see `pw-jack`).
* May need to use midi events directly (instead of intermediate internal representation). E.g. `track::to_lane_events`
* May need to use midi events directly (instead of intermediate internal representation). E.g. `track::from_midi_events`
may not be necessary. In particular tail shifts will become simpler. This will require
* To handle ignored/unused events along with notes and sustain.
* Midi events have starting times relative to previous ones. May need some indexing mechanism (e.g. a range tree)
Expand Down
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use eframe::{self, egui, CreationContext};
use egui_extras::{Size, StripBuilder};

use crate::engine::{Engine, EngineCommand, StatusEvent, TransportTime};
use crate::lane::Lane;
use crate::project::Project;
use crate::stave::{Stave, StaveTime};
use crate::track::Track;

enum Message {
UpdateTransportTime(TransportTime),
Expand All @@ -31,7 +31,7 @@ impl EmApp {
pub fn new(
ctx: &CreationContext,
engine_command_send: mpsc::Sender<Box<EngineCommand>>,
track: Arc<RwLock<Lane>>,
track: Arc<RwLock<Track>>,
project: Project,
) -> EmApp {
let (message_sender, message_receiver) = mpsc::channel();
Expand Down
2 changes: 1 addition & 1 deletion src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use midly::MidiMessage;
use vst::event::Event;
use vst::plugin::Plugin;

use crate::lane::MIDI_CC_SUSTAIN_ID;
use crate::midi_vst::Vst;
use crate::track::MIDI_CC_SUSTAIN_ID;

/// uSecs from the start.
pub type TransportTime = u64;
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use eframe::{egui, Theme};

use crate::app::EmApp;
use crate::config::Config;
use crate::lane::Lane;
use crate::midi::SmfSource;
use crate::project::Project;
use crate::track::Track;
use crate::track_source::TrackSource;

mod app;
Expand All @@ -15,11 +15,11 @@ mod common;
mod config;
mod engine;
mod events;
mod lane;
mod midi;
mod midi_vst;
mod project;
mod stave;
mod track;
mod track_source;
mod util;

Expand Down Expand Up @@ -66,7 +66,7 @@ pub fn main() {
.unwrap();
}

let mut track = Lane::default();
let mut track = Track::default();
track.load_from(&project.current_snapshot_path());
let track = Arc::new(RwLock::new(track));
{
Expand Down
2 changes: 1 addition & 1 deletion src/midi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use midly::MidiMessage::Controller;
use midly::{Format, Header, MidiMessage, Smf, Timing, Track, TrackEvent};

use crate::engine::{EngineEvent, EventSource, TransportTime};
use crate::lane::{ChannelId, ControllerId, Level, Pitch};
use crate::track::{ChannelId, ControllerId, Level, Pitch};

pub struct SmfSource {
events: Vec<TrackEvent<'static>>,
Expand Down
43 changes: 23 additions & 20 deletions src/stave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use ordered_float::OrderedFloat;

use crate::common::VersionId;
use crate::engine::TransportTime;
use crate::lane::{
EventId, Lane, LaneEvent, LaneEventType, Level, Note, Pitch, MIDI_CC_SUSTAIN_ID,
use crate::track::{
EventId, Level, Note, Pitch, Track, TrackEvent, TrackEventType, MIDI_CC_SUSTAIN_ID,
};
use crate::{lane, Pix};
use crate::{track, Pix};

pub type StaveTime = i64;

Expand Down Expand Up @@ -70,7 +70,7 @@ impl NotesSelection {
}
}

fn contains(&self, ev: &LaneEvent) -> bool {
fn contains(&self, ev: &TrackEvent) -> bool {
self.selected.contains(&ev.id)
}
}
Expand All @@ -79,9 +79,9 @@ fn to_transport_time(value: StaveTime) -> TransportTime {
value.max(0) as TransportTime
}

impl From<&TimeSelection> for lane::TimeSelection {
impl From<&TimeSelection> for track::TimeSelection {
fn from(value: &TimeSelection) -> Self {
lane::TimeSelection {
track::TimeSelection {
from: to_transport_time(value.from),
to: to_transport_time(value.to),
}
Expand All @@ -90,7 +90,7 @@ impl From<&TimeSelection> for lane::TimeSelection {

#[derive(Debug)]
pub struct Stave {
pub track: Arc<RwLock<Lane>>,
pub track: Arc<RwLock<Track>>,
pub time_left: StaveTime,
pub time_right: StaveTime,
pub view_rect: Rect,
Expand All @@ -100,21 +100,21 @@ pub struct Stave {
pub note_draw: Option<NoteDraw>,
pub note_selection: NotesSelection,

pub lane_version: VersionId,
pub track_version: VersionId,
}

impl PartialEq for Stave {
fn eq(&self, other: &Self) -> bool {
// This eq implementation helps so egui knows when not to re-render.
let mut lane_equals = false;
let mut track_equals = false;
if let Ok(track) = &mut self.track.try_read() {
lane_equals = self.lane_version == track.version;
track_equals = self.track_version == track.version;
}
self.time_left == other.time_left
&& self.time_right == other.time_right
&& self.cursor_position == other.cursor_position
&& self.view_rect == other.view_rect
&& lane_equals
&& track_equals
}
}

Expand All @@ -130,10 +130,10 @@ pub struct StaveUiResponse {
}

impl Stave {
pub fn new(track: Arc<RwLock<Lane>>) -> Stave {
pub fn new(track: Arc<RwLock<Track>>) -> Stave {
Stave {
track: track.clone(),
lane_version: 0,
track_version: 0,
time_left: 0,
time_right: chrono::Duration::minutes(5).num_microseconds().unwrap(),
view_rect: Rect::NOTHING,
Expand Down Expand Up @@ -232,7 +232,7 @@ impl Stave {
for i in 0..track.events.len() {
let event = &track.events[i];
match &event.event {
LaneEventType::Note(note) => {
TrackEventType::Note(note) => {
if let Some(y) = key_ys.get(&note.pitch) {
let is_hovered = Self::event_hovered(
&pitch_hovered,
Expand All @@ -256,7 +256,7 @@ impl Stave {
);
}
}
LaneEventType::Controller(v) if v.controller_id == MIDI_CC_SUSTAIN_ID => {
TrackEventType::Controller(v) if v.controller_id == MIDI_CC_SUSTAIN_ID => {
if let Some(y) = key_ys.get(&PIANO_DAMPER_LINE) {
let at = event.at as StaveTime;
self.draw_cc(
Expand All @@ -276,7 +276,7 @@ impl Stave {
)*/
}
}
self.lane_version = track.version;
self.track_version = track.version;

self.draw_cursor(
&painter,
Expand Down Expand Up @@ -332,7 +332,7 @@ impl Stave {
fn event_hovered(
pitch_hovered: &Option<Pitch>,
time_hovered: &Option<StaveTime>,
event: &LaneEvent,
event: &TrackEvent,
pitch: &Pitch,
) -> bool {
if let Some(t) = &time_hovered {
Expand Down Expand Up @@ -479,7 +479,7 @@ impl Stave {
track.edit_events(
&(|ev| {
if self.note_selection.contains(ev) {
if let LaneEventType::Note(note) = &mut ev.event {
if let TrackEventType::Note(note) = &mut ev.event {
Some(note)
} else {
None
Expand Down Expand Up @@ -521,7 +521,7 @@ impl Stave {
time: &Option<StaveTime>,
pitch: &Option<Pitch>,
) {
// TODO Extract the drag procedure? See also update_time_selection.
// TODO Extract the drag pattern? See also update_time_selection.
let drag_button = PointerButton::Middle;
if response.clicked_by(drag_button) {
self.note_draw = None;
Expand Down Expand Up @@ -617,7 +617,6 @@ impl Stave {
keys: &BTreeMap<Pitch, Pix>,
pitch_hovered: &Option<Pitch>,
) {
let is_black_key = |tone: &Pitch| vec![1, 3, 6, 8, 10].contains(&(tone % 12));
for (pitch, y) in keys {
let mut color = if is_black_key(&pitch) {
Rgba::from_rgb(0.05, 0.05, 0.05)
Expand Down Expand Up @@ -677,6 +676,10 @@ impl Stave {
}
}

fn is_black_key(tone: &Pitch) -> bool {
vec![1, 3, 6, 8, 10].contains(&(tone % 12))
}

fn closest_pitch(pitch_ys: &BTreeMap<Pitch, Pix>, pointer_pos: Pos2) -> Pitch {
*pitch_ys
.iter()
Expand Down
Loading

0 comments on commit 05f9445

Please sign in to comment.