Skip to content

Commit da40512

Browse files
committed
A track knows its number, its part, its catalogue and who played it
Five columns on `song`, which is where facts true of the song kind and of nothing else belong. The track number stops being a prefix somebody typed into a title and becomes data a client can sort and draw. - `track` — where it sits in the album; 0 when nobody said. - `part` — the suite or book inside the work. Water Music is *one* album with three suites, and this is what says which. Not folded into `album`, because they answer different questions: the album is what you put on, the part is where you are inside it. - `catalogue` — `BWV 988`. The only name for a classical work that survives translation, so it is what two recordings of one piece agree on when their titles do not. - `performer` — **who played it, which is not who wrote it.** Every one of the 457 Bach recordings currently claims an artist of "Johann Sebastian Bach", which is true of the composition and false of the recording. Ishizaka, Lehman and the Marine Band are three performances and the library could not tell them apart. - `bpm` — 0 almost everywhere, deliberately. **This is not a breaking change, and it was offered as one.** `mutations.txt` says an argument may be added — a payload without a field decodes to that field's default — so the new arguments go on the end of `AddSong` and every entry already in a log replays as what it was: a song with no track number and no catalogue. What does move is the table shape, which is what `schema_version` is for; it goes to 2 and each peer rebuilds its tables from the log on the next open. `track_albums` is `track_details` and returns all of it. Still beside `Item` rather than folded into it, for the reason `media` exists: these are song facts, and putting them on the kind-neutral row would put a join behind every list. Two things fall out of it. The scanner reads what a real file actually states — `TRCK`, `ALBUMARTIST` and `TBPM` — so a tagged library arrives with a performer and a tempo, while a wiki transcode arrives with neither and says so. And the table has a `#` column, with the text shortened through a **middle** ellipsis: `Wrapping::None` does not shorten a string, it draws the whole thing over the next column, which is the overlap. The middle goes because the ends are what identify a movement — clipping `Prelude No. 14 in F-sharp minor, BWV 859` at the end leaves the half that is identical across all twenty-four. The demo's rows carry the new fields empty for now; filling them is the next commit. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XcBd33WHuwVJf6eCw7CpeG
1 parent 71f5a90 commit da40512

14 files changed

Lines changed: 6188 additions & 3420 deletions

File tree

‎domain/mutations.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# build. A verb or an argument may be ADDED — a payload without a field decodes
33
# to that field's default. Removing or renaming a verb, or dropping or retyping
44
# an argument, breaks every entry already written, and the check refuses it.
5-
AddSong title:Text artist:Text album:Text duration_ms:Integer file:Text
5+
AddSong title:Text artist:Text album:Text duration_ms:Integer file:Text track:Integer part:Text catalogue:Text performer:Text bpm:Integer
66
CreatePlaylist name:Text
77
AddToPlaylist playlist_id:Id(playlist) media_id:Id(media)
88
RemoveFromPlaylist playlist_id:Id(playlist) media_id:Id(media)

‎domain/schema.sql‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,50 @@ CREATE TABLE IF NOT EXISTS media (
3636
-- kind to prove it.
3737
CREATE TABLE IF NOT EXISTS song (
3838
media_id BLOB PRIMARY KEY NOT NULL REFERENCES media(id),
39-
album TEXT NOT NULL
39+
album TEXT NOT NULL,
40+
-- Where it sits in the album. 0 is "not known", which is honest for a
41+
-- single somebody typed in and for a file with no tag — and sorts first,
42+
-- which is where an unplaced track belongs.
43+
track BIGINT NOT NULL,
44+
-- The division of the work this belongs to, when a work has them: a suite
45+
-- inside Water Music, a book of the Well-Tempered Clavier, an act. Empty
46+
-- when the album is undivided, which is most of them.
47+
--
48+
-- Not folded into `album`, because they answer different questions: the
49+
-- album is what you put on, and this is where you are inside it. A client
50+
-- that groups by album still groups correctly when a work has three
51+
-- suites, and one that shows the division can.
52+
part TEXT NOT NULL,
53+
-- The catalogue number: `BWV 988`, `K. 525`, `Op. 23`. Empty for music
54+
-- nobody catalogued.
55+
--
56+
-- This is the only *stable* name a classical work has. Titles are
57+
-- translated, transliterated and abbreviated differently by every
58+
-- publisher; the number is the same in every language and every edition,
59+
-- which makes it the thing to match on when two recordings are the same
60+
-- piece.
61+
catalogue TEXT NOT NULL,
62+
-- Who played it, which is not who wrote it. `media.creator` carries the
63+
-- composer, because that is the line a kind-neutral list draws under a
64+
-- title — and for three hundred years of music the performer is a
65+
-- different person, sometimes several of them on one album.
66+
--
67+
-- Empty when unknown rather than repeating the composer: saying nothing is
68+
-- better than saying something false, and a client can tell them apart.
69+
performer TEXT NOT NULL,
70+
-- Beats per minute, 0 when unknown.
71+
--
72+
-- Two honest sources, and neither is a machine listening to the audio. A
73+
-- tagged file states it in `TBPM` and the scanner reads it. Failing that,
74+
-- the *tempo marking* is one: `Allegro` and `Adagio` are instructions
75+
-- about speed, written by the composer, and the conventional metronome
76+
-- ranges for them are what a performer reads. Taking the middle of the
77+
-- range for the marking is an approximation and is stored as one.
78+
--
79+
-- What is not allowed here is a number with no source. 0 means nobody
80+
-- said, and a movement titled `Variatio 7 a 1 ovvero 2 Clav` is a
81+
-- movement nobody said a tempo for.
82+
bpm BIGINT NOT NULL
4083
);
4184

4285
-- A playlist. "Favourites" is one of these and nothing special: a heart in a

‎domain/src/functions.rs‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
//! error rather than a missing row on a device, and a write says what it
2424
//! changed — which is what an incrementally maintained query will need.
2525
26+
// A mutation's arguments are the wire format: each one is a field in the
27+
// log, and every verb here is generated into several functions — the
28+
// authoring call, the dispatch arm, the foreign export. So the lint fires
29+
// on code nobody wrote, and the refactor it asks for (bundle them into a
30+
// struct) would put a second shape between a caller and the entry, which
31+
// is the thing `mutations.txt` exists to pin down.
32+
#![allow(clippy::too_many_arguments)]
33+
2634
use petros_schema::prelude::*;
2735

2836
// `#[mutation]` and `#[query]` each emit a method on the peer a foreign caller
@@ -60,6 +68,16 @@ pub fn add_song(
6068
album: String,
6169
duration_ms: i64,
6270
file: String,
71+
// Everything below was added after the log had entries in it. That is
72+
// allowed and is why the arguments are at the end: a payload written
73+
// before they existed decodes with each at its default, so an old entry
74+
// replays as a song with no track number and no catalogue — which is
75+
// exactly what it was.
76+
track: i64,
77+
part: String,
78+
catalogue: String,
79+
performer: String,
80+
bpm: i64,
6381
) -> Result {
6482
if title.trim().is_empty() {
6583
return Err("a song needs a title".into());
@@ -104,6 +122,16 @@ pub fn add_song(
104122
db.put(&Song {
105123
media_id: id,
106124
album: album.trim().to_string(),
125+
// Negatives are not a position in an album, and neither is a number
126+
// past any plausible one: clamped rather than refused, because a bad
127+
// track number is not a reason to lose the recording.
128+
track: track.clamp(0, 999),
129+
part: part.trim().to_string(),
130+
catalogue: catalogue.trim().to_string(),
131+
performer: performer.trim().to_string(),
132+
// The slowest marking anybody writes is around 20 and the fastest
133+
// around 300; outside that it is not a tempo.
134+
bpm: if (20..=300).contains(&bpm) { bpm } else { 0 },
107135
})?;
108136
Ok(())
109137
}
@@ -420,13 +448,18 @@ pub fn artists(db: &mut Db) -> Result<Vec<crate::schema::Artist>> {
420448
/// The column a table draws beside the artist. Read from the song end, so a
421449
/// kind with no albums contributes nothing and needs no case here.
422450
#[query]
423-
pub fn track_albums(db: &mut Db) -> Result<Vec<crate::schema::TrackAlbum>> {
451+
pub fn track_details(db: &mut Db) -> Result<Vec<crate::schema::TrackDetail>> {
424452
Ok(db
425453
.select(Song::all())
426454
.into_iter()
427-
.map(|s| crate::schema::TrackAlbum {
455+
.map(|s| crate::schema::TrackDetail {
428456
media_id: s.media_id,
429457
album: s.album,
458+
track: s.track,
459+
part: s.part,
460+
catalogue: s.catalogue,
461+
performer: s.performer,
462+
bpm: s.bpm,
430463
})
431464
.collect())
432465
}

‎domain/src/lib.rs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ pub use petros_schema::Id;
3434
#[cfg(feature = "storage")]
3535
petros::app!(HarkenApp {
3636
schema: crate::schema::SCHEMA,
37-
// 1, because `song` and `favorite` changed shape when the library stopped
38-
// being songs and became media of a kind. Every peer rebuilds its tables
39-
// from the log on the next open; the log itself did not move.
40-
schema_version: 1,
37+
// 2, because `song` grew the columns that say where a track sits in its
38+
// album — the number, the part, the catalogue, who played it, the tempo.
39+
// Every peer rebuilds its tables from the log on the next open; the log
40+
// itself did not move, and entries written before those arguments existed
41+
// replay with them at their defaults.
42+
schema_version: 2,
4143
apply: crate::functions::apply,
4244
fill_auto: crate::functions::fill_auto,
4345
});

‎domain/src/schema.rs‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,31 @@ petros_schema::row! {
8989
tracks: i64,
9090
};
9191

92-
/// Which album a track is on, for a client drawing a column of them.
92+
/// What is true of a track as a *song*, for a client drawing those columns.
9393
///
94-
/// A pair rather than a field on [`Item`], and that is the whole point:
95-
/// `album` is true of the *song* kind and lives on `song`, so folding it
96-
/// into the kind-neutral library row would put a join behind every list —
97-
/// the thing `media` exists to avoid. A screen that wants the column asks
98-
/// for it and joins in memory; a screen that does not, does not pay.
99-
TrackAlbum => {
94+
/// Beside [`Item`] rather than folded into it, and that is the whole
95+
/// point: every field here is true of the song kind and lives on `song`,
96+
/// so putting them on the kind-neutral library row would put a join behind
97+
/// every list — the thing `media` exists to avoid. A screen that wants
98+
/// these asks for them and joins in memory; a screen that does not, does
99+
/// not pay. It was `TrackAlbum` when `album` was the only one.
100+
TrackDetail => {
100101
media_id: Id<tables::Media> => String { |id| id.to_string() },
101102
album: String,
103+
/// Where it sits in the album; 0 when nobody said.
104+
track: i64,
105+
/// The suite or book inside the work, when the work has them. Empty
106+
/// otherwise, which is most albums.
107+
part: String,
108+
/// `BWV 988`. The one name for a classical work that survives
109+
/// translation, so it is what two recordings of one piece agree on.
110+
catalogue: String,
111+
/// Who played it. `Item::creator` is who *wrote* it, and for this
112+
/// repertoire they are three hundred years apart.
113+
performer: String,
114+
/// Beats per minute; 0 when nobody said. See `schema.sql` for what
115+
/// counts as somebody saying.
116+
bpm: i64,
102117
};
103118

104119
/// Whoever made something, as a sidebar lists them.

‎domain/tests/client_client.rs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ fn the_client_runs_the_module() {
3939
String::new(),
4040
0,
4141
String::new(),
42+
0,
43+
String::new(),
44+
String::new(),
45+
String::new(),
46+
0,
4247
)
4348
.expect("the module accepted it");
4449
client
@@ -48,6 +53,11 @@ fn the_client_runs_the_module() {
4853
String::new(),
4954
0,
5055
String::new(),
56+
0,
57+
String::new(),
58+
String::new(),
59+
String::new(),
60+
0,
5161
)
5262
.expect("second");
5363
// A playlist to heart onto: there is no favourites table, so a heart is
@@ -77,6 +87,11 @@ fn the_client_runs_the_module() {
7787
String::new(),
7888
0,
7989
String::new(),
90+
0,
91+
String::new(),
92+
String::new(),
93+
String::new(),
94+
0,
8095
)
8196
.expect_err("a blank title is refused");
8297
assert!(
@@ -97,6 +112,11 @@ fn the_client_runs_the_module() {
97112
String::new(),
98113
0,
99114
String::new(),
115+
0,
116+
String::new(),
117+
String::new(),
118+
String::new(),
119+
0,
100120
)
101121
.expect("still working");
102122
assert_eq!(client.library(favs.clone()).unwrap().len(), 3);
@@ -263,6 +283,11 @@ fn the_peer_maintains_its_library() {
263283
String::new(),
264284
0,
265285
String::new(),
286+
0,
287+
String::new(),
288+
String::new(),
289+
String::new(),
290+
0,
266291
)
267292
.unwrap();
268293
settle(&client, &mut held);

‎domain/tests/client_latency.rs‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ fn the_cost_of_the_thread() {
4343
String::new(),
4444
0,
4545
String::new(),
46+
0,
47+
String::new(),
48+
String::new(),
49+
String::new(),
50+
0,
4651
);
4752
let mut bytes = Vec::new();
4853
ciborium::into_writer(&raw, &mut bytes).unwrap();
@@ -91,6 +96,11 @@ fn fsync_or_wasm() {
9196
String::new(),
9297
0,
9398
String::new(),
99+
0,
100+
String::new(),
101+
String::new(),
102+
String::new(),
103+
0,
94104
))
95105
.unwrap();
96106
let mut ts = vec![];
@@ -103,6 +113,11 @@ fn fsync_or_wasm() {
103113
String::new(),
104114
0,
105115
String::new(),
116+
0,
117+
String::new(),
118+
String::new(),
119+
String::new(),
120+
0,
106121
))
107122
.unwrap();
108123
ts.push(t.elapsed().as_secs_f64() * 1000.0);
@@ -141,6 +156,11 @@ fn one_tap_at_a_fixed_depth() {
141156
String::new(),
142157
0,
143158
String::new(),
159+
0,
160+
String::new(),
161+
String::new(),
162+
String::new(),
163+
0,
144164
))
145165
.unwrap();
146166
}
@@ -151,6 +171,11 @@ fn one_tap_at_a_fixed_depth() {
151171
String::new(),
152172
0,
153173
String::new(),
174+
0,
175+
String::new(),
176+
String::new(),
177+
String::new(),
178+
0,
154179
))
155180
.unwrap();
156181
ts.push(t.elapsed().as_secs_f64() * 1000.0);
@@ -204,6 +229,11 @@ fn a_bulk_mutation_row_by_row() {
204229
String::new(),
205230
0,
206231
String::new(),
232+
0,
233+
String::new(),
234+
String::new(),
235+
String::new(),
236+
0,
207237
);
208238
let mut bytes = Vec::new();
209239
ciborium::into_writer(&raw, &mut bytes).unwrap();
@@ -290,6 +320,11 @@ fn maintained_against_re_read_on_the_client_path() {
290320
String::new(),
291321
0,
292322
String::new(),
323+
0,
324+
String::new(),
325+
String::new(),
326+
String::new(),
327+
0,
293328
))
294329
.unwrap();
295330
}
@@ -315,6 +350,11 @@ fn maintained_against_re_read_on_the_client_path() {
315350
String::new(),
316351
0,
317352
String::new(),
353+
0,
354+
String::new(),
355+
String::new(),
356+
String::new(),
357+
0,
318358
))
319359
.unwrap();
320360

@@ -393,6 +433,11 @@ fn what_crosses_the_boundary() {
393433
String::new(),
394434
0,
395435
String::new(),
436+
0,
437+
String::new(),
438+
String::new(),
439+
String::new(),
440+
0,
396441
)
397442
.unwrap();
398443
}
@@ -407,6 +452,11 @@ fn what_crosses_the_boundary() {
407452
String::new(),
408453
0,
409454
String::new(),
455+
0,
456+
String::new(),
457+
String::new(),
458+
String::new(),
459+
0,
410460
)
411461
.unwrap();
412462

‎domain/tests/client_no_module.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ fn mutating_without_a_module_is_refused_rather_than_ignored() {
2929
String::new(),
3030
0,
3131
String::new(),
32+
0,
33+
String::new(),
34+
String::new(),
35+
String::new(),
36+
0,
3237
)
3338
.expect_err("no module is loaded");
3439
assert!(

0 commit comments

Comments
 (0)