A CD-shaped music player for Linux, with local playback and Cider integration.
Add cassette player and interactive vinyl controls
yappologisticbb90cdb7f7f6
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 6704556..bc84110 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -39,7 +39,7 @@ find_package(PkgConfig REQUIRED)pkg_check_modules(TAGLIB REQUIRED IMPORTED_TARGET taglib>=2.0)qt_add_library(spun_core STATICsrc/symbol.cpp src/symbol.h src/typography.cpp src/typography.h- src/listening.cpp src/listening.h+ src/listening.cpp src/listening.h src/tapesound.cpp src/tapesound.h src/vinylnoise.cpp src/vinylnoise.hsrc/musicactions.cpp src/musicactions.hsrc/library.cpp src/library.h src/lyrics.cpp src/lyrics.h src/artwork.cpp src/artwork.hsrc/player.cpp src/player.h src/disc.cpp src/disc.h src/mpris.cpp src/mpris.h@@ -67,7 +67,7 @@ function(spun_application target)# Compile QML at build time, preserving existing resource URLs and the UI.qt_add_qml_module(${target} URI SpunUi VERSION 1.0 NO_PLUGINNO_RESOURCE_TARGET_PATH RESOURCE_PREFIX "/" OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${target}-qml"- QML_FILES qml/SpunButton.qml qml/SpunSlider.qml qml/QuickJump.qml qml/NextTrackTip.qml qml/SavedQueuePicker.qml qml/Tonearm.qml qml/SpunText.qml qml/FontPicker.qml qml/SpunStateLayer.qml qml/SpunSpring.qml qml/SpunPopupEnter.qml qml/SpunStyle.qml qml/TrackContent.qml qml/SpunSearchField.qml qml/MenuEntry.qml qml/PreferenceSwitch.qml qml/TrackMenu.qml qml/Main.qml qml/LibraryPanel.qml qml/SpunToolTip.qml qml/IconButton.qml qml/Glyph.qml)+ QML_FILES qml/SpunButton.qml qml/SpunSlider.qml qml/SeekSlider.qml qml/QuickJump.qml qml/NextTrackTip.qml qml/SavedQueuePicker.qml qml/Tonearm.qml qml/CassetteReels.qml qml/SpunText.qml qml/FontPicker.qml qml/SpunStateLayer.qml qml/SpunSpring.qml qml/SpunPopupEnter.qml qml/SpunStyle.qml qml/TrackContent.qml qml/SpunSearchField.qml qml/MenuEntry.qml qml/PreferenceSwitch.qml qml/TrackMenu.qml qml/Main.qml qml/LibraryPanel.qml qml/SpunToolTip.qml qml/IconButton.qml qml/Glyph.qml)# Preserve the exact SVGs and URLs; Qt's default threshold leaves many of# these small resources uncompressed. Parsed symbols are already cached.if(QT_FEATURE_zstd)diff --git a/qml/CassetteReels.qml b/qml/CassetteReels.qmlnew file mode 100644index 0000000..14cc1c2--- /dev/null+++ b/qml/CassetteReels.qml@@ -0,0 +1,104 @@+import QtQuick++Item {+ id: tape+ required property var app+ readonly property real leftAngle: outgoing ? app.outgoingCassetteLeftAngle : app.cassetteLeftAngle+ readonly property real rightAngle: outgoing ? app.outgoingCassetteRightAngle : app.cassetteRightAngle+ property bool outgoing: false+ readonly property real progress: Math.max(0, Math.min(1, app.progress))+ Repeater {+ model: 2+ Item {+ required property int index+ x: (index === 0 ? 113.6 : 296.4) - 40; y: 150.2+ width: 80; height: 80+ Rectangle {+ anchors.centerIn: parent+ width: 78+ scale: Math.sqrt(1936 + 3993 * (index === 0 ? 1 - tape.progress : tape.progress)) / 78+ height: width; radius: width / 2+ id: woundTape+ color: "#30251e"; border.width: 1; border.color: "#171513"+ Repeater {+ model: 28+ Rectangle {+ required property int index+ anchors.centerIn: parent+ width: 37 + (woundTape.width - 39) * (index + 1) / 29+ height: width; radius: width / 2; color: "transparent"+ border.width: .35; border.color: index % 3 ? "#69523b" : "#181512"+ opacity: .48+ }+ }+ Behavior on scale { enabled: tape.app.animate && !tape.outgoing; NumberAnimation { duration: 200 } }+ }+ // Clear flange and fixed lighting sit over the moving tape pack.+ Rectangle {+ anchors.centerIn: parent; width: 76; height: 76; radius: 38+ color: "#07d7e0de"; border.width: .6; border.color: "#30d9ddcc"+ Rectangle { anchors.centerIn: parent; width: 69; height: 69; radius: 34.5; color: "transparent"; border.width: .5; border.color: "#1ee2e6d8" }+ }+ Rectangle {+ anchors.centerIn: parent; anchors.verticalCenterOffset: 1.5+ width: 43; height: 43; radius: 21.5; color: "#90090808"+ }+ Rectangle {+ anchors.centerIn: parent; width: 40; height: 40; radius: 20+ gradient: Gradient {+ GradientStop { position: 0; color: "#ece4d0" }+ GradientStop { position: .45; color: Qt.tint("#ccc5af", Qt.alpha(tape.app.accent, .08)) }+ GradientStop { position: 1; color: "#8d8878" }+ }+ border.width: .7; border.color: "#5a584d"+ Rectangle { anchors.centerIn: parent; width: 36; height: 36; radius: 18; color: "transparent"; border.width: .6; border.color: "#80fff4d4" }+ Item {+ objectName: "cassetteReel" + parent.parent.index+ anchors.fill: parent+ rotation: parent.parent.index === 0 ? tape.leftAngle : tape.rightAngle+ Repeater {+ model: 3+ Rectangle {+ required property int index+ x: 16; y: 4; width: 8; height: 7; radius: 2.5+ color: "#37372f"; border.width: .6; border.color: "#aca592"+ transform: Rotation { origin.x: 4; origin.y: 16; angle: index * 120 }+ }+ }+ Rectangle { anchors.centerIn: parent; width: 18; height: 18; radius: 9; color: "#111414"; border.width: .6; border.color: "#8c8978" }+ Repeater {+ model: 6+ Rectangle {+ required property int index+ x: 18.3; y: 10.2; width: 3.4; height: 4.2; radius: .5+ color: "#d6ceba"+ transform: Rotation { origin.x: 1.7; origin.y: 9.8; angle: index * 60 }+ }+ }+ }+ }+ Rectangle {+ anchors.centerIn: parent; width: 76; height: 76; radius: 38+ gradient: Gradient {+ GradientStop { position: 0; color: "#12ffffff" }+ GradientStop { position: .3; color: "#00ffffff" }+ GradientStop { position: 1; color: "#18000000" }+ }+ }+ }+ }+ Rectangle {+ x: 24; y: 88; width: 362; height: 43; radius: 2+ color: "transparent"+ border.width: 0+ Rectangle { x: 7; y: 7; width: 28; height: 28; radius: 1; color: "#34362f"+ SpunText { anchors.centerIn: parent; text: "A"; font.pixelSize: 21; color: "#e5dfcb" }+ }+ Rectangle { x: 45; y: 32; width: parent.width - 55; height: .7; color: "#807c6c" }+ SpunText {+ x: 45; y: 9; width: parent.width - 55; height: 22+ text: tape.app.deckPlayer.album || tape.app.deckPlayer.title || "Cassette"+ color: "#30332c"; font.pixelSize: SpunStyle.body; font.italic: true; elide: Text.ElideRight+ }+ }+}diff --git a/qml/Main.qml b/qml/Main.qmlindex 9ab0be1..4a514eb 100644--- a/qml/Main.qml+++ b/qml/Main.qml@@ -9,12 +9,14 @@ ApplicationWindow {title: "Spun"visible: truewidth: miniMode ? 300 : sideOpen ? 860 : 530- height: miniMode ? 354 : 730+ height: miniMode ? (showHorizontalSeek ? 382 : 354) : 730minimumWidth: 300; maximumWidth: 860minimumHeight: 300; maximumHeight: 730color: "transparent"flags: Qt.Window | Qt.FramelessWindowHint | (miniPinned && !native.supportsBlur ? Qt.WindowStaysOnTopHint : 0)font.family: SpunStyle.family+ readonly property bool cassette: player.medium === "cassette"+ onCassetteChanged: Qt.callLater(function() { stopSwap(); scrubber.cancelScrub(); updateMask() })readonly property bool vinyl: player.vinylonVinylChanged: Qt.callLater(updateMask)property bool useCider: !testMode && root.ciderService.available@@ -36,6 +38,29 @@ ApplicationWindow {onTriggered: root.refreshOpenCiderDetails()}property var deckPlayer: useCider ? root.ciderService : player+ readonly property string cassetteTrackIdentity: (useCider ? "cider:" : "local:") + (deckPlayer.trackKey || "")+ onCassetteTrackIdentityChanged: Qt.callLater(syncTapeSound)+ function syncTapeSound() { tapeSound.observe(useCider ? "cider" : "local", deckPlayer.trackKey || "") }+ Binding { target: tapeSound; property: "enabled"; value: root.cassette && player.cassetteSounds }+ Binding { target: tapeSound; property: "volume"; value: root.deckPlayer.volume }+ Binding { target: vinylNoise; property: "active"; value: root.vinyl && root.deckPlayer.playing && !root.needleDragging }+ Binding { target: vinylNoise; property: "crackle"; value: player.vinylCrackle }+ Binding { target: vinylNoise; property: "hiss"; value: player.vinylStatic }+ Binding { target: vinylNoise; property: "volume"; value: root.deckPlayer.volume }+ readonly property bool needleDragging: armLoader.item ? armLoader.item.dragging : false+ function skipGroove() {+ if (!vinyl || !player.vinylSkips || !deckPlayer.playing || needleDragging || swapRunning || (useCider && (!ciderService.canSeek || ciderService.controlBusy))) return false+ const jump = player.vinylSpeed === 45 ? 60000/45 : 1800+ if (deckPlayer.position < 5000 || deckPlayer.position + jump > deckPlayer.duration - 5000) return false+ deckPlayer.seek(deckPlayer.position + jump)+ return true+ }+ Timer {+ id: grooveSkipTimer; objectName: "grooveSkipTimer"+ interval: 45000 + Math.floor(Math.random()*35000); repeat: true+ running: root.vinyl && player.vinylSkips && root.deckPlayer.playing && !root.needleDragging+ onTriggered: { root.skipGroove(); interval = 45000 + Math.floor(Math.random()*35000) }+ }onUseCiderChanged: { recoveryPopup.close(); quickJump.close(); savedQueuePicker.close(); clearQueueSelection(); cleanupPopup.close(); qualityPopup.close(); if(libraryDragging)endLibraryDrag(false); preferences.close(); crossfadeMenu.close(); queueMenu.close(); cancelQueueDrag(); songMenu.close(); musicBrowser.closeActions(); if (!useCider) libraryOpen = false; if (useCider) player.pause(); root.ciderService.queueVisible = queueOpen && useCider; discFlipped = false; closeQueueSearch(); Qt.callLater(presentDisc); syncLyrics() }property bool lyricsView: falseproperty real swapOffset: 0@@ -271,6 +296,13 @@ ApplicationWindow {onBackgroundBlurChanged: { native.effects(root, backgroundBlur); Qt.callLater(updateMask) }property bool muted: falseproperty real rememberedVolume: .65+ property real cassetteLeftAngle: 0+ property real cassetteRightAngle: 0+ property real outgoingCassetteLeftAngle: 0+ property real outgoingCassetteRightAngle: 0+ readonly property real vinylDegreesPerSecond: player.vinylSpeed === 45 ? 270 : player.vinylSpeed === 33 ? 200 : 9+ readonly property bool showHorizontalSeek: player.horizontalSeek && !cassette && deckPlayer.count > 0+ onShowHorizontalSeekChanged: Qt.callLater(updateMask)property real spinAngle: 0property real spinSpeed: 0property real wavePhase: 0@@ -368,9 +400,14 @@ ApplicationWindow {const now = Date.now()const dt = Math.min(.05, (now-lastTime)/1000)lastTime = now- const target = root.deckPlayer.playing ? 9 : 0+ const target = root.deckPlayer.playing ? (root.vinyl ? root.vinylDegreesPerSecond : 9) : 0root.spinSpeed += (target-root.spinSpeed)*Math.min(1,dt*2.2)if (!root.discFlipped) root.spinAngle = (root.spinAngle+root.spinSpeed*dt)%360+ if (root.cassette && !root.discFlipped && root.deckPlayer.playing) {+ const position = Math.max(0, Math.min(1, root.progress))+ root.cassetteLeftAngle = (root.cassetteLeftAngle + dt * 10000 / Math.sqrt(1936 + 3993 * (1-position))) % 360+ root.cassetteRightAngle = (root.cassetteRightAngle + dt * 10000 / Math.sqrt(1936 + 3993 * position)) % 360+ }if (root.deckPlayer.playing) root.wavePhase=(root.wavePhase+dt*2.8)%(2*Math.PI)}}@@ -472,7 +509,7 @@ ApplicationWindow {HoverHandler { id: platterHover }// Shadow is circular, so the player keeps its silhouette on any wallpaper.Repeater {- model: 7+ model: root.cassette ? 0 : 7Rectangle {required property int indexanchors.centerIn: parent@@ -489,8 +526,9 @@ ApplicationWindow {opacity: root.outgoingOpacitytransform: Translate { x: root.outgoingOffset }sourceComponent: Item {- Disc { vinyl: root.vinyl; anchors.fill: parent; artwork: presentation.outgoing; rotation: root.outgoingAngle }- Disc { vinyl: root.vinyl; anchors.fill: parent; overlay: true }+ Disc { cassette: root.cassette; shellColor: root.surface; vinyl: root.vinyl; anchors.fill: parent; artwork: presentation.outgoing; rotation: root.cassette ? 0 : root.outgoingAngle }+ Disc { cassette: root.cassette; shellColor: root.surface; vinyl: root.vinyl; anchors.fill: parent; overlay: true }+ Loader { anchors.fill: parent; active: root.cassette; sourceComponent: CassetteReels { app: root; outgoing: true } }}}Item {@@ -511,23 +549,24 @@ ApplicationWindow {}front: Item {anchors.fill: parent- Disc { vinyl: root.vinyl;+ Disc { cassette: root.cassette; shellColor: root.surface; vinyl: root.vinyl;id: faceobjectName: "discFace"anchors.fill: parentartwork: presentation.artwork- rotation: root.spinAngle+ rotation: root.cassette ? 0 : root.spinAngle}- Disc { vinyl: root.vinyl; anchors.fill: parent; overlay: true }+ Disc { cassette: root.cassette; shellColor: root.surface; vinyl: root.vinyl; anchors.fill: parent; overlay: true }+ Loader { objectName: "cassetteReelsLoader"; anchors.fill: parent; active: root.cassette; sourceComponent: CassetteReels { app: root } }}back: Item {objectName: "discBack"anchors.fill: parent- Disc { vinyl: root.vinyl; anchors.fill: parent; labelColor: root.surface }+ Disc { cassette: root.cassette; shellColor: root.surface; vinyl: root.vinyl; anchors.fill: parent; labelColor: root.surface }SpunText {objectName: "discAlbumTitle"id: albumHeading- x: 84; y: 52; width: 242; height: 50+ x: root.cassette ? 38 : 84; y: root.cassette ? 80 : 52; width: root.cassette ? 334 : 242; height: root.cassette ? 40 : 50text: root.lyricsView ? root.deckPlayer.title : root.discDetails.title || root.deckPlayer.album || "Unknown album"font.pixelSize: root.miniMode ? 22 : SpunStyle.title; font.weight: Font.NormalfontSizeMode: Text.Fit; minimumPixelSize: root.miniMode ? 17 : 15@@ -540,7 +579,7 @@ ApplicationWindow {SpunText {id: albumArtistobjectName: "discAlbumArtist"- x: 72; y: 107; width: 266; height: 20+ x: 72; y: root.cassette ? 123 : 107; width: 266; height: 20text: root.lyricsView ? root.deckPlayer.artist : root.discDetails.artist || root.deckPlayer.artistfont.pixelSize: root.miniMode ? 18 : SpunStyle.body; color: root.mutedInkhorizontalAlignment: Text.AlignHCenter; elide: Text.ElideRight@@ -550,7 +589,7 @@ ApplicationWindow {}SpunText {objectName: "discAlbumYear"- x: 72; y: 131; width: 266; height: 18+ x: 72; y: root.cassette ? 145 : 131; width: 266; height: 18text: root.lyricsView ? "" : root.discDetails.year || ""font.pixelSize: root.miniMode ? 16 : SpunStyle.caption; color: root.accenthorizontalAlignment: Text.AlignHCenter@@ -558,7 +597,7 @@ ApplicationWindow {ListView {id: albumListobjectName: "albumTrackList"- x: 68; y: 262; width: 274; height: root.miniMode ? 76 : 82+ x: root.cassette ? 38 : 68; y: root.cassette ? 176 : 262; width: root.cassette ? 334 : 274; height: root.cassette ? 116 : root.miniMode ? 76 : 82readonly property int rowHeight: root.miniMode ? 36 : 32property int rememberedRow: 0property string rememberedAlbum: ""@@ -642,7 +681,7 @@ ApplicationWindow {ListView {id: lyricListobjectName: "lyricList"- x: 76; y: 260; width: 258; height: 84+ x: root.cassette ? 42 : 76; y: root.cassette ? 176 : 260; width: root.cassette ? 326 : 258; height: root.cassette ? 116 : 84visible: root.lyricsView && lyrics.lines.length > 0model: lyrics.lines; clip: true; spacing: 8boundsBehavior: Flickable.StopAtBounds@@ -713,7 +752,7 @@ ApplicationWindow {}}Column {- x: 80; y: 262; width: 250; spacing: 4+ x: 80; y: root.cassette ? 182 : 262; width: 250; spacing: 4visible: root.lyricsView && !lyrics.lines.lengthSpunText {width: parent.width; text: lyrics.loading ? "Loading lyrics…" : lyrics.message@@ -731,7 +770,7 @@ ApplicationWindow {Row {objectName: "discBackFooter"anchors.horizontalCenter: parent.horizontalCenter- y: 348; height: 36; spacing: 10+ y: root.cassette ? 298 : 348; height: 36; spacing: 10SpunText {anchors.verticalCenter: parent.verticalCentervisible: !root.lyricsView && root.albumTracks.length > 0@@ -762,7 +801,7 @@ ApplicationWindow {}Column {- x: 80; y: 264; width: 250; spacing: 5+ x: 80; y: root.cassette ? 182 : 264; width: 250; spacing: 5visible: !root.lyricsView && root.useCider && !root.albumTracks.lengthSpunText {width: parent.width; horizontalAlignment: Text.AlignHCenter; wrapMode: Text.WordWrap@@ -805,6 +844,7 @@ ApplicationWindow {}Loader {+ id: armLoaderobjectName: "tonearmLoader"anchors.fill: parentactive: root.vinyl@@ -818,7 +858,7 @@ ApplicationWindow {// Stop the old sequence without releasing that new image.discSwap.stop(); root.resetSwap()if (!root.animate || root.discFlipped || !root.visible || !native.exposed) { presentation.releaseOutgoing(); return }- scrubber.cancelScrub(); root.outgoingAngle = root.spinAngle+ scrubber.cancelScrub(); root.outgoingAngle = root.spinAngle; root.outgoingCassetteLeftAngle = root.cassetteLeftAngle; root.outgoingCassetteRightAngle = root.cassetteRightAngleroot.swapOffset = 440; root.outgoingOffset = 0; root.outgoingOpacity = 1; root.incomingOpacity = 0discSwap.departureTime = SpunStyle.enter; discSwap.arrivalTime = SpunStyle.herodiscSwap.start()@@ -844,7 +884,7 @@ ApplicationWindow {ProgressRing {objectName: "progressRing"anchors.fill: parent- visible: root.deckPlayer.count > 0+ visible: !root.cassette && root.deckPlayer.count > 0progress: scrubber.scrubbing ? scrubber.previewFraction : root.progressphase: root.wavePhaseamplitude: root.deckPlayer.playing ? 2.8 : 0@@ -861,7 +901,7 @@ ApplicationWindow {readonly property bool canSeek: !root.swapRunning && root.deckPlayer.duration > 0 && (!root.useCider || root.ciderService.canSeek)readonly property bool showPreview: canSeek && (scrubbing || (containsMouse && onRim(mouseX,mouseY)))cursorShape: canSeek && onRim(mouseX,mouseY) ? Qt.PointingHandCursor : Qt.ArrowCursor- function onRim(x,y) { let r=Math.hypot(x-220,y-220); return r > 205 && r < 224 }+ function onRim(x,y) { let r=Math.hypot(x-220,y-220); return !root.cassette && r > 205 && r < 224 }function updatePreview(x,y) {let a=Math.atan2(y-220,x-220)+Math.PI/2if (a < 0) a += 2*Math.PI@@ -880,6 +920,13 @@ ApplicationWindow {onCanceled: cancelScrub()onWheel: wheel => { if (root.discFlipped && !onRim(wheel.x,wheel.y)) { wheel.accepted=false; return }; root.deckPlayer.volume = Math.max(0, Math.min(1, root.deckPlayer.volume + wheel.angleDelta.y/2400)); wheel.accepted=true }}+ SeekSlider {+ app: root+ objectName: "cassetteSeek"+ visible: root.cassette && root.deckPlayer.count > 0+ x: 70; y: 365; width: 300; height: 36++ }DropArea {anchors.fill: parentonEntered: drag => { if (!drag.hasUrls && !drag.hasText) drag.accepted=false }@@ -911,17 +958,22 @@ ApplicationWindow {color: root.surfaceSpunText { anchors.centerIn: parent; text: root.time(root.deckPlayer.duration * scrubber.previewFraction); font.pixelSize: SpunStyle.caption; color: root.accent }}+ SeekSlider {+ app: root; objectName: "miniHorizontalSeek"+ visible: root.miniMode && root.showHorizontalSeek+ x: 50; y: 294; width: 200; height: 32+ }Timer { id: miniReveal; interval: 1400 }Item {visible: root.miniMode- x: 50; y: 268; width: 200; height: 84+ x: 50; y: 268; width: 200; height: root.showHorizontalSeek ? 112 : 84HoverHandler { id: miniDockHover }}Rectangle {id: miniControlsobjectName: "miniControls"visible: root.miniMode- x: 50; y: 302; width: 200; height: 48; radius: 24+ x: 50; y: root.showHorizontalSeek ? 330 : 302; width: 200; height: 48; radius: 24color: root.surfaceopacity: platterHover.hovered || miniDockHover.hovered || miniControlsHover.hovered || miniReveal.running || miniPrevious.visualFocus || miniPlay.visualFocus || miniNext.visualFocus || miniRestore.visualFocus ? 1 : 0Behavior on opacity { NumberAnimation { duration: root.transitionTime; easing.type: Easing.BezierSpline; easing.bezierCurve: SpunStyle.effectsCurve } }@@ -941,7 +993,7 @@ ApplicationWindow {id: deckobjectName: "playerDeck"visible: !root.miniMode- x: 62; y: 533; width: 406; height: 144; radius: SpunStyle.panelRadius+ x: 62; y: 533; width: 406; height: 144 + (root.showHorizontalSeek ? 28 : 0); radius: SpunStyle.panelRadiuscolor: root.surface; border.width: 0MouseArea { anchors.fill: parent; onPressed: root.startSystemMove() }SpunText {@@ -972,8 +1024,12 @@ ApplicationWindow {text: root.time(root.deckPlayer.position); color: root.mutedInkfont.pixelSize: 13}+ SeekSlider {+ app: root; objectName: "horizontalSeek"+ visible: root.showHorizontalSeek; x: 24; y: 72; width: 358; height: 32+ }Row {- x: 16; y: 80; spacing: 4+ x: 16; y: 80 + (root.showHorizontalSeek ? 28 : 0); spacing: 4IconButton { objectName: "shuffleButton"; y: 4; selected: root.deckPlayer.shuffle; glyphName: "shuffle"; tip: root.deckPlayer.shuffle ? "Shuffle on" : "Shuffle off"; enabled: !root.useCider || !root.ciderService.controlBusy; ink: root.deckPlayer.shuffle ? root.accent : root.mutedInk; hoverFill: root.hoverFill; onClicked: root.deckPlayer.shuffle = !root.deckPlayer.shuffle }IconButton { objectName: "previousButton"; y: 4; glyphName: "previous"; tip: "Previous track · Ctrl+←"; ink: root.ink; hoverFill: root.hoverFill; enabled: root.useCider ? root.ciderService.canPrevious : player.count > 0; onClicked: root.deckPlayer.previous() }IconButton {@@ -995,17 +1051,17 @@ ApplicationWindow {}}- IconButton { x: 256; y: 84; glyphName: root.deckPlayer.volume > 0 ? "volume" : "mute"; tip: "Mute · M"; ink: root.mutedInk; hoverFill: root.hoverFill; onClicked: root.toggleMute() }+ IconButton { x: 256; y: 84 + (root.showHorizontalSeek ? 28 : 0); glyphName: root.deckPlayer.volume > 0 ? "volume" : "mute"; tip: "Mute · M"; ink: root.mutedInk; hoverFill: root.hoverFill; onClicked: root.toggleMute() }SpunSlider {id: volumeSliderobjectName: "volumeSlider"- x: 300; y: 86; width: 44; height: 36+ x: 300; y: 86 + (root.showHorizontalSeek ? 28 : 0); width: 44; height: 36from: 0; to: 1; stepSize: .05; value: root.deckPlayer.volumeonMoved: root.deckPlayer.volume = valueAccessible.name: "Volume"}- IconButton { id: menuButton; objectName: "menuButton"; x: 350; y: 84; glyphName: "more"; tip: "More actions"; ink: root.mutedInk; hoverFill: root.hoverFill; onClicked: root.openSettings() }+ IconButton { id: menuButton; objectName: "menuButton"; x: 350; y: 84 + (root.showHorizontalSeek ? 28 : 0); glyphName: "more"; tip: "More actions"; ink: root.mutedInk; hoverFill: root.hoverFill; onClicked: root.openSettings() }}@@ -1582,19 +1638,20 @@ ApplicationWindow {width: parent.width; height: 48; spacing: 4Repeater {id: recordChoices- model: ["CD", "Vinyl"]+ model: ["CD", "Vinyl", "Cassette"]delegate: AbstractButton {id: recordChoicerequired property string modelData- objectName: modelData === "CD" ? "cdStyleButton" : "vinylStyleButton"- width: (preferenceItems.width - 4) / 2; height: SpunStyle.target- text: modelData; checkable: true; autoExclusive: true; checked: player.vinyl === (modelData === "Vinyl"); hoverEnabled: true+ required property int index+ objectName: modelData.toLowerCase() + "StyleButton"+ width: (preferenceItems.width - 8) / 3; height: SpunStyle.target+ text: modelData; checkable: true; autoExclusive: true; checked: player.medium === modelData.toLowerCase(); hoverEnabled: trueAccessible.name: modelData + " appearance"; Accessible.checked: checked- Keys.onLeftPressed: recordChoices.itemAt(0).forceActiveFocus(Qt.TabFocusReason)- Keys.onRightPressed: recordChoices.itemAt(1).forceActiveFocus(Qt.TabFocusReason)+ Keys.onLeftPressed: recordChoices.itemAt(Math.max(0,index-1)).forceActiveFocus(Qt.TabFocusReason)+ Keys.onRightPressed: recordChoices.itemAt(Math.min(2,index+1)).forceActiveFocus(Qt.TabFocusReason)Keys.onReturnPressed: clicked()Keys.onEnterPressed: clicked()- onClicked: player.vinyl = modelData === "Vinyl"+ onClicked: player.medium = modelData.toLowerCase()onActiveFocusChanged: if(activeFocus) preferenceScroll.reveal(this)background: Rectangle {radius: 20 * theme.radius; color: "transparent"@@ -1628,8 +1685,32 @@ ApplicationWindow {Glyph { anchors.right: parent.right; anchors.rightMargin: 12; anchors.verticalCenter: parent.verticalCenter; name: "down"; ink: root.mutedInk }}}+ Column {+ width: parent.width; spacing: 4; visible: root.vinyl+ SpunText { x: 12; text: "Record speed"; color: root.mutedInk; font.pixelSize: SpunStyle.caption }+ Row {+ width: parent.width; spacing: 4+ Repeater {+ model: ["Relaxed", "33⅓ RPM", "45 RPM"]+ SpunButton {+ required property string modelData+ required property int index+ objectName: "vinylSpeed" + index+ width: (preferenceItems.width - 8) / 3; height: 40+ text: modelData; checkable: true; autoExclusive: true; tonal: checked; checked: player.vinylSpeed === [0,33,45][index]+ onClicked: player.vinylSpeed = [0,33,45][index]+ onActiveFocusChanged: if(activeFocus)preferenceScroll.reveal(this)+ }+ }+ }+ }+ PreferenceSwitch { objectName: "horizontalSeekToggle"; app: root; width: parent.width; visible: !root.cassette; height: visible ? implicitHeight : 0; text: "Horizontal progress bar"; glyphName: "minus"; checked: player.horizontalSeek; onToggled: player.horizontalSeek = checked; onActiveFocusChanged: if(activeFocus)preferenceScroll.reveal(this) }+ PreferenceSwitch { objectName: "vinylCrackleToggle"; app: root; width: parent.width; visible: root.vinyl; height: visible ? implicitHeight : 0; text: "Vinyl crackle"; glyphName: "volume"; checked: player.vinylCrackle; onToggled: player.vinylCrackle = checked; onActiveFocusChanged: if(activeFocus)preferenceScroll.reveal(this) }+ PreferenceSwitch { objectName: "vinylStaticToggle"; app: root; width: parent.width; visible: root.vinyl; height: visible ? implicitHeight : 0; text: "Surface hiss"; glyphName: "volume"; checked: player.vinylStatic; onToggled: player.vinylStatic = checked; onActiveFocusChanged: if(activeFocus)preferenceScroll.reveal(this) }+ PreferenceSwitch { objectName: "vinylSkipsToggle"; app: root; width: parent.width; visible: root.vinyl; height: visible ? implicitHeight : 0; text: "Occasional groove skips"; Accessible.description: "Occasionally jumps playback forward by one record revolution"; glyphName: "next"; checked: player.vinylSkips; onToggled: player.vinylSkips = checked; onActiveFocusChanged: if(activeFocus)preferenceScroll.reveal(this) }PreferenceSwitch { objectName: "miniPinToggle"; app: root; width: parent.width; text: "Keep Mini on top"; glyphName: "pin"; checked: player.miniOnTop; onToggled: player.miniOnTop = checked; onActiveFocusChanged: if (activeFocus) preferenceScroll.reveal(this) }PreferenceSwitch { objectName: "blurToggle"; app: root; width: parent.width; visible: native.supportsBlur; height: visible ? implicitHeight : 0; text: "Blur background"; glyphName: "blur"; checked: player.backgroundBlur; onToggled: player.backgroundBlur = checked; onActiveFocusChanged: if (activeFocus) preferenceScroll.reveal(this) }+ PreferenceSwitch { objectName: "cassetteSoundsToggle"; app: root; width: parent.width; visible: root.cassette; height: visible ? implicitHeight : 0; text: "Cassette sounds"; glyphName: "volume"; checked: player.cassetteSounds; onToggled: player.cassetteSounds = checked; onActiveFocusChanged: if (activeFocus) preferenceScroll.reveal(this) }PreferenceSwitch { objectName: "motionToggle"; app: root; width: parent.width; text: "Animations"; glyphName: "motion"; checked: player.motion; onToggled: player.motion = checked; onActiveFocusChanged: if (activeFocus) preferenceScroll.reveal(this) }Rectangle { x: 12; width: parent.width - 24; height: 1; color: root.hairline }PreferenceSwitch { objectName: "rememberSessionToggle"; app: root; width: parent.width; text: "Remember Cider session"; glyphName: "queue"; checked: root.listeningService.rememberSession; enabled: !root.listeningService.busy; onToggled: root.listeningService.rememberSession = checked; onActiveFocusChanged: if (activeFocus) preferenceScroll.reveal(this) }diff --git a/qml/SeekSlider.qml b/qml/SeekSlider.qmlnew file mode 100644index 0000000..a2536bc--- /dev/null+++ b/qml/SeekSlider.qml@@ -0,0 +1,37 @@+import QtQuick+import Spun 1.0++SpunSlider {+ id: control+ required property var app+ enabled: visible && !app.swapRunning && app.deckPlayer.duration > 0 && (!app.useCider || app.ciderService.canSeek)+ value: app.progress+ valueText: app.time(value * app.deckPlayer.duration)+ Accessible.name: "Playback position"+ onMoved: app.deckPlayer.seek(value * app.deckPlayer.duration)+ background: Item {+ x: 4; y: 4; width: control.availableWidth; height: control.availableHeight+ readonly property real head: parent.visualPosition * (width - 4) + 2+ opacity: parent.enabled ? 1 : SpunStyle.disabledOpacity+ ProgressRing {+ objectName: control.objectName + "Wave"+ width: Math.max(0, parent.head - 5); height: parent.height+ visible: width > 0+ linear: true; progress: 1+ phase: control.app.wavePhase+ amplitude: control.app.deckPlayer.playing ? 2.8 : 0+ accent: control.app.accent+ Behavior on amplitude { NumberAnimation { duration: SpunStyle.enter } }+ }+ Rectangle {+ anchors.verticalCenter: parent.verticalCenter+ x: Math.min(parent.width, parent.head + 5); width: parent.width - x+ height: 4; radius: 2; color: theme.colors.outline+ }+ Rectangle {+ anchors.verticalCenter: parent.verticalCenter; anchors.right: parent.right+ width: 3; height: 3; radius: 1.5; color: control.app.accent+ visible: control.app.progress < .95+ }+ }+}diff --git a/qml/Tonearm.qml b/qml/Tonearm.qmlindex 1c1a315..0a1a37d 100644--- a/qml/Tonearm.qml+++ b/qml/Tonearm.qml@@ -1,28 +1,77 @@import QtQuick-// Decorative scene-graph geometry: no images, effects, timers or pointer handlers.+// Lightweight geometry with a bounded stylus gesture and damped return motion.Item {id: armobjectName: "vinylTonearm"required property var appreadonly property bool motion: app.animate && visible && app.visible && native.exposed- readonly property bool engaged: visible && app.deckPlayer.count > 0 && app.deckPlayer.playing- property real lowered: engaged ? 1 : 0- property real groove: Math.max(0, Math.min(1, app.progress))- readonly property real armAngle: -4 + lowered * (10 + 20 * groove)+ readonly property bool engaged: visible && app.deckPlayer.count > 0 && (app.deckPlayer.playing || landing)+ readonly property bool canSeek: visible && app.deckPlayer.duration > 0 && (!app.useCider || app.ciderService.canSeek)+ property bool dragging: false+ property real dragAngle: -4+ property real rawAngle: -4+ property real grabOffset: 0+ property real pointerDistance: 210+ property string dragTrack: ""+ property bool wasPlaying: false+ property bool landing: false+ property real landingProgress: 0+ readonly property real previewProgress: Math.max(0, Math.min(1, (rawAngle - 6) / 20))+ property real lowered: dragging ? .12 : engaged ? 1 : 0+ property real groove: landing ? landingProgress : Math.max(0, Math.min(1, app.progress))+ property real armAngle: dragging ? dragAngle : engaged ? 6 + 20 * groove : -4+ Behavior on armAngle {+ enabled: arm.motion && !arm.dragging+ SpringAnimation { id: angleSpring; spring: 6; damping: .55; epsilon: .01 }+ }+ function cancelDrag(resume) {+ if (!dragging) return+ dragging = false; landing = false+ if (resume && wasPlaying && dragTrack === app.cassetteTrackIdentity) app.deckPlayer.play()+ }+ function dropNeedle() {+ if (!dragging) return+ const valid = canSeek && dragTrack === app.cassetteTrackIdentity && rawAngle >= 4 && rawAngle <= 28 && pointerDistance > 120 && pointerDistance < 290+ const position = previewProgress+ if (!valid) { dragging = false; return }+ landingProgress = position; landing = true; landingTimeout.restart()+ dragging = false+ app.deckPlayer.seek(Math.min(app.deckPlayer.duration - 1, app.deckPlayer.duration * position))+ app.deckPlayer.play()+ }+ function confirmLanding() {+ if (landing && app.deckPlayer.playing && Math.abs(app.progress - landingProgress) < .025) {+ landing = false; landingTimeout.stop()+ }+ }+ onVisibleChanged: if (!visible) cancelDrag(true)+ onCanSeekChanged: if (!canSeek) cancelDrag(false)+ Timer { id: landingTimeout; interval: 1200; onTriggered: arm.landing = false }+ Connections {+ target: arm.app+ function onCassetteTrackIdentityChanged() { arm.cancelDrag(false); arm.landing = false }+ }+ Connections {+ target: arm.app.deckPlayer+ function onPositionChanged() { arm.confirmLanding() }+ function onPlayingChanged() { arm.confirmLanding() }+ }readonly property color gold: Qt.tint("#c6a25a", Qt.alpha(app.accent, .12))readonly property color glint: Qt.lighter(gold, 1.5)readonly property color shade: Qt.darker(gold, 1.6)Behavior on lowered {- enabled: arm.motion+ enabled: arm.motion && !arm.draggingNumberAnimation { id: liftMotion; duration: SpunStyle.hero; easing.type: Easing.BezierSpline; easing.bezierCurve: SpunStyle.standardCurve }}- Behavior on groove {- enabled: arm.motion && arm.engaged- NumberAnimation { id: grooveMotion; duration: SpunStyle.navigate; easing.type: Easing.Linear }- }onMotionChanged: if (!motion) {- liftMotion.complete(); grooveMotion.complete()+ liftMotion.complete(); angleSpring.complete()+ }+ SpunToolTip {+ parent: arm; x: 184; y: 60+ visible: needleHit.containsMouse || needleHit.activeFocus+ delay: arm.dragging ? 0 : 650+ text: arm.dragging ? arm.app.time(arm.previewProgress * arm.app.deckPlayer.duration) : "Drag the needle to seek"}// The pivot rests at the record's edge; the stylus stays outside the label.Item {@@ -33,6 +82,7 @@ Item {color: arm.app.surface; border.width: 1; border.color: arm.shade}Item {+ id: shaftobjectName: "tonearmShaft"rotation: arm.armAngletransformOrigin: Item.TopLeft@@ -66,8 +116,61 @@ Item {Rectangle { x: 4; y: 10; width: 6; height: 2; radius: 1; color: arm.gold }Rectangle { x: 6; y: 23; width: 2; height: 5; radius: 1; color: arm.glint }}+}Rectangle { x: -7; y: -7; width: 14; height: 14; radius: 7; color: arm.gold; border.width: 1; border.color: arm.glint }Rectangle { x: -3; y: -1; width: 6; height: 2; radius: 1; rotation: -35; color: arm.shade }}+ // Pointer coordinates must stay fixed while the shaft rotates beneath them.+ MouseArea {+ id: needleHit; objectName: "needleHandle"+ anchors.fill: parent+ enabled: arm.canSeek; hoverEnabled: true; preventStealing: true+ acceptedButtons: Qt.LeftButton+ activeFocusOnTab: true+ readonly property point tip: {+ const angle = arm.armAngle * Math.PI / 180+ return Qt.point(378 - 197 * Math.sin(angle), 100 + 197 * Math.cos(angle))+ }+ containmentMask: QtObject {+ function contains(point) { return Math.hypot(point.x - needleHit.tip.x, point.y - needleHit.tip.y) <= 27 }+ }+ cursorShape: arm.dragging ? Qt.ClosedHandCursor : Qt.OpenHandCursor+ Accessible.role: Accessible.Slider+ Accessible.name: "Needle position"+ Accessible.description: "Drag onto the grooves to seek and play. Arrow keys seek; Enter starts playback; Escape cancels dragging."+ onPressed: mouse => {+ if (Math.hypot(mouse.x - tip.x, mouse.y - tip.y) > 27) { mouse.accepted = false; return }+ forceActiveFocus()+ arm.dragAngle = arm.armAngle; arm.rawAngle = arm.armAngle+ arm.grabOffset = Math.atan2(378 - mouse.x, mouse.y - 100) * 180 / Math.PI - arm.armAngle+ arm.dragTrack = arm.app.cassetteTrackIdentity; arm.wasPlaying = arm.app.deckPlayer.playing+ arm.pointerDistance = Math.hypot(mouse.x - 378, mouse.y - 100)+ arm.dragging = true; arm.landing = false; landingTimeout.stop()+ if (arm.wasPlaying) arm.app.deckPlayer.pause()+ }+ onPositionChanged: mouse => {+ if (!pressed || !arm.dragging) return+ const dx = mouse.x - 378, dy = mouse.y - 100+ arm.pointerDistance = Math.hypot(dx, dy)+ arm.rawAngle = Math.atan2(-dx, dy) * 180 / Math.PI - arm.grabOffset+ arm.dragAngle = Math.max(-8, Math.min(38, arm.rawAngle))+ }+ onReleased: arm.dropNeedle()+ onCanceled: arm.cancelDrag(true)+ onWheel: wheel => { wheel.accepted = false }+ Keys.onShortcutOverride: event => { if ([Qt.Key_Escape,Qt.Key_Left,Qt.Key_Right,Qt.Key_Return,Qt.Key_Enter].includes(event.key)) event.accepted = true }+ Keys.onEscapePressed: arm.cancelDrag(true)+ Keys.onLeftPressed: arm.app.deckPlayer.seek(Math.max(0,arm.app.deckPlayer.position - 5000))+ Keys.onRightPressed: arm.app.deckPlayer.seek(Math.min(arm.app.deckPlayer.duration,arm.app.deckPlayer.position + 5000))+ Keys.onReturnPressed: arm.app.deckPlayer.play()+ Keys.onEnterPressed: arm.app.deckPlayer.play()+ Rectangle {+ x: needleHit.tip.x - 22; y: needleHit.tip.y - 25; width: 44; height: 50+ rotation: arm.armAngle; radius: 10; color: "transparent"+ border.width: needleHit.activeFocus && !needleHit.containsMouse && !arm.dragging ? 1.5 : 0+ border.color: arm.app.accent+ }+ }+}diff --git a/src/cider.h b/src/cider.hindex 8bab161..d61d1eb 100644--- a/src/cider.h+++ b/src/cider.h@@ -31,6 +31,7 @@ class Cider : public QObject {Q_PROPERTY(bool liveConnected READ liveConnected NOTIFY liveChanged)Q_PROPERTY(bool libraryVisible READ libraryVisible WRITE setLibraryVisible NOTIFY connectionChanged)Q_PROPERTY(bool available READ available NOTIFY trackChanged)+ Q_PROPERTY(QString trackKey READ trackKey NOTIFY trackChanged)Q_PROPERTY(QString title READ title NOTIFY trackChanged)Q_PROPERTY(QString artist READ artist NOTIFY trackChanged)Q_PROPERTY(QString album READ album NOTIFY trackChanged)@@ -94,6 +95,7 @@ public:Q_INVOKABLE void reconnect();bool available() const { return m_available; }~Cider() override;+ QString trackKey() const { return count() ? m_track : QString{}; }QString title() const { return m_title.isEmpty() ? "Cider" : m_title; }QString artist() const { return m_artist; }QString album() const { return m_album; }diff --git a/src/disc.cpp b/src/disc.cppindex 971a2cb..ca29aa3 100644--- a/src/disc.cpp+++ b/src/disc.cpp@@ -55,6 +55,7 @@ void Disc::paint(QPainter *p) {const double side = qMin(width(), height());p->translate((width() - side) / 2, (height() - side) / 2);p->scale(side / 1000, side / 1000);+ if (m_cassette) { paintCassette(p); return; }if (m_vinyl) { paintVinyl(p); return; }const QPointF center(500, 500);QPainterPath annulus;@@ -153,9 +154,129 @@ void Disc::paintVinyl(QPainter *p) {p->setPen(QPen(QColor(255,255,255,40),1));p->drawEllipse(center,21,21);}+void Disc::paintCassette(QPainter *p) {+ if(m_overlay)return;+ const QRectF shell(3,165,994,670);+ QLinearGradient plastic(0,165,160,835);+ plastic.setColorAt(0,m_shellColor.lighter(150));plastic.setColorAt(.08,m_shellColor.lighter(118));+ plastic.setColorAt(.46,m_shellColor.lighter(115));plastic.setColorAt(.94,m_shellColor.darker(118));+ plastic.setColorAt(.95,m_shellColor.darker(165));plastic.setColorAt(1,m_shellColor.darker(210));+ p->setPen(Qt::NoPen);p->setBrush(plastic);p->drawRoundedRect(shell,38,38);+ p->setBrush(Qt::NoBrush);p->setPen(QPen(QColor(0,0,0,165),5));p->drawRoundedRect(shell.adjusted(3,3,-3,-3),35,35);+ p->setPen(QPen(QColor(255,255,255,32),2));p->drawRoundedRect(shell.adjusted(10,9,-10,-10),30,30);+ p->setPen(QPen(QColor(0,0,0,70),2));p->drawRoundedRect(shell.adjusted(18,17,-18,-18),26,26);+ // Internal posts and the tape guides show through the smoked shell.+ if(!m_labelColor.isValid()) {+ for(int side:{0,1}) {+ p->save();if(side){p->translate(1000,0);p->scale(-1,1);}+ QPainterPath brace;brace.moveTo(52,648);brace.lineTo(98,620);brace.lineTo(155,698);brace.lineTo(108,774);+ p->setBrush(Qt::NoBrush);p->setPen(QPen(QColor(0,0,0,120),12,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));p->drawPath(brace);+ p->translate(0,-2);p->setPen(QPen(QColor(171,169,147,35),3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));p->drawPath(brace);p->translate(0,2);+ QRadialGradient recess(QPointF(130,745),54);recess.setColorAt(0,QColor(0,0,0,180));recess.setColorAt(.7,QColor(0,0,0,130));recess.setColorAt(1,QColor(0,0,0,0));+ p->setPen(Qt::NoPen);p->setBrush(recess);p->drawEllipse(QPointF(130,745),54,54);+ QRadialGradient roller(QPointF(124,737),39);roller.setColorAt(0,QColor("#858371"));roller.setColorAt(.65,QColor("#414238"));roller.setColorAt(.86,QColor("#242821"));roller.setColorAt(1,QColor("#aaa38b"));+ p->setBrush(roller);p->drawEllipse(QPointF(130,745),30,30);+ p->setBrush(QColor("#171a17"));p->drawEllipse(QPointF(130,745),9,9);+ p->setBrush(QColor("#949583"));p->drawEllipse(QPointF(130,745),4,4);+ p->restore();+ }+ QPainterPath tape;tape.moveTo(252,567);tape.lineTo(104,729);tape.cubicTo(84,751,103,778,130,778);tape.lineTo(870,778);tape.cubicTo(897,778,916,751,896,729);tape.lineTo(748,567);+ p->setBrush(Qt::NoBrush);p->setPen(QPen(QColor("#17100d"),9));p->drawPath(tape);+ p->setPen(QPen(QColor("#76503a"),3));p->drawPath(tape);+ // Subtle smoke tint belongs to the plastic above the mechanism.+ p->setPen(Qt::NoPen);p->setBrush(QColor(55,53,43,35));p->drawRoundedRect(shell.adjusted(20,20,-20,-20),23,23);+ }+ // Matte grain is baked into the shell once, not regenerated by reel motion.+ QRandomGenerator grain(61);+ for(int i=0;i<3600;++i) {+ p->setPen(QPen(i%2?QColor(255,255,255,9):QColor(0,0,0,18),1));+ p->drawPoint(QPointF(23+grain.bounded(954),185+grain.bounded(630)));+ }+ const QRectF label(54,m_labelColor.isValid()?195:210,892,m_labelColor.isValid()?610:423);+ QPainterPath clip;clip.addRoundedRect(label,24,24);+ p->save();p->setClipPath(clip);+ if(m_labelColor.isValid())p->fillPath(clip,m_labelColor);+ else {+ if(m_art.isNull() && m_fallback.isNull()) {static const QImage shared=fallbackArt();m_fallback=shared;}+ const auto &art=m_art.isNull()?m_fallback:m_art;+ const double scale=qMax(label.width()/art.width(),label.height()/art.height());+ const QSizeF crop(label.width()/scale,label.height()/scale);+ p->drawImage(label,art,QRectF((art.width()-crop.width())/2,(art.height()-crop.height())/2,crop.width(),crop.height()));+ p->fillPath(clip,QColor(226,215,188,16));+ }+ p->restore();+ p->setBrush(Qt::NoBrush);p->setPen(QPen(QColor(0,0,0,115),3));p->drawPath(clip);+ p->setPen(QPen(QColor(247,232,202,45),1));p->drawRoundedRect(label.adjusted(3,3,-3,-3),22,22);+ if(!m_labelColor.isValid()) {+ // Slight paper fibers and an uneven ink edge keep the label tactile.+ const QRectF paper(58.5,214.6,883,105);+ QLinearGradient stock(0,214,0,320);stock.setColorAt(0,QColor("#ece5cf"));stock.setColorAt(1,QColor("#d9cfb5"));+ p->setBrush(stock);p->setPen(QPen(QColor("#726b56"),1));p->drawRoundedRect(paper,3,3);+ p->save();p->setClipRect(paper.adjusted(2,2,-2,-2));+ QRandomGenerator fibers(108);+ p->setPen(QPen(QColor(86,72,42,20),.7));+ for(int i=0;i<950;++i){const QPointF a(60+fibers.bounded(879),216+fibers.bounded(101));p->drawLine(a,a+QPointF(1+fibers.bounded(4),0));}+ p->restore();+ // A recessed smoked window joins the two reel wells.+ const QRectF window(132,356,736,216);+ p->setPen(QPen(QColor(0,0,0,200),8));p->setBrush(QColor("#141516"));p->drawRoundedRect(window,24,24);+ p->setPen(QPen(QColor(230,235,233,44),2));p->setBrush(Qt::NoBrush);p->drawRoundedRect(window.adjusted(4,5,-4,-4),20,20);+ QLinearGradient glass(0,368,0,560);+ glass.setColorAt(0,QColor(194,205,205,34));glass.setColorAt(.35,QColor(99,107,107,12));glass.setColorAt(1,QColor(0,0,0,60));+ p->setPen(Qt::NoPen);p->setBrush(glass);p->drawRoundedRect(window.adjusted(8,8,-8,-8),16,16);+ p->setPen(QPen(QColor("#684735"),6));p->drawLine(QPointF(371,511),QPointF(629,511));+ p->setPen(QPen(QColor("#aa7c53"),1));p->drawLine(QPointF(371,508),QPointF(629,508));+ for(int i=0;i<9;++i) {+ const double x=420+i*20;p->setPen(QPen(QColor(223,213,186,i%4==0?150:75),2));+ p->drawLine(QPointF(x,440),QPointF(x,i%4==0?468:455));+ }+ // Thin reflection on the clear window, with the mechanism visible below.+ QPainterPath reflection;reflection.moveTo(145,365);reflection.lineTo(260,365);reflection.lineTo(205,559);reflection.lineTo(145,559);reflection.closeSubpath();+ p->setPen(Qt::NoPen);p->setBrush(QColor(228,237,230,9));p->drawPath(reflection);+ // Molded stiffening ribs and the raised tape-head housing.+ for(int i=0;i<18;++i) {+ if(i==8 || i==9)continue;+ const int x=75+i*50;p->setPen(QPen(QColor(0,0,0,95),4));p->drawLine(QPointF(x,672),QPointF(x+29,672));+ p->setPen(QPen(QColor(255,255,255,22),2));p->drawLine(QPointF(x,676),QPointF(x+29,676));+ }+ QPainterPath lip;lip.moveTo(202,818);lip.lineTo(237,707);lip.lineTo(763,707);lip.lineTo(798,818);lip.closeSubpath();+ QLinearGradient molded(0,706,0,822);molded.setColorAt(0,m_shellColor.lighter(130));molded.setColorAt(.08,m_shellColor.darker(125));molded.setColorAt(1,m_shellColor.darker(160));+ p->setPen(QPen(QColor(255,255,255,30),2));p->setBrush(molded);p->drawPath(lip);+ for(int x:{290,710}) {+ p->setPen(QPen(QColor(255,255,255,30),2));p->setBrush(QColor("#101112"));p->drawEllipse(QPointF(x,778),19,19);+ p->setBrush(QColor("#08090a"));p->setPen(Qt::NoPen);p->drawEllipse(QPointF(x,776),14,14);+ }+ p->setBrush(QColor("#0b0c0d"));p->drawRoundedRect(QRectF(425,758,150,43),7,7);+ p->setPen(QPen(QColor("#714b34"),5));p->drawLine(QPointF(427,778),QPointF(573,778));+ p->setPen(QPen(QColor("#afa58a"),2));p->drawLine(QPointF(451,789),QPointF(549,789));+ p->setPen(Qt::NoPen);p->setBrush(QColor("#988872"));p->drawRoundedRect(QRectF(477,781,46,8),1,1);+ for(int x:{367,618}) {p->setBrush(QColor("#0b0c0d"));p->drawRoundedRect(QRectF(x,767,15,31),6,6);}+ }+ // The two molded shell halves meet at a narrow seam. Grip ribs catch light+ // on one edge only, so they read as plastic rather than an outer UI border.+ for(int side:{0,1}) for(int row=0;row<10;++row) {+ const qreal x=side?954:21,y=324+row*29;+ p->setPen(QPen(QColor(0,0,0,110),3));p->drawLine(QPointF(x,y),QPointF(x+24,y));+ p->setPen(QPen(QColor(255,255,255,25),1));p->drawLine(QPointF(x,y+2),QPointF(x+24,y+2));+ }+ // Recessed fasteners, including the center screw above the head opening.+ const QList<QPointF> screws=m_labelColor.isValid()+ ? QList<QPointF>{{32,195},{968,195},{32,802},{968,802}}+ : QList<QPointF>{{32,195},{968,195},{32,802},{968,802},{500,673}};+ for(QPointF point:screws) {+ QRadialGradient well(point,21);well.setColorAt(0,QColor(0,0,0,210));well.setColorAt(.7,QColor(0,0,0,180));well.setColorAt(1,QColor(0,0,0,0));+ p->setPen(Qt::NoPen);p->setBrush(well);p->drawEllipse(point,21,21);+ p->setPen(Qt::NoPen);p->setBrush(QColor(0,0,0,145));p->drawEllipse(point+QPointF(0,2),15,15);+ QRadialGradient steel(point-QPointF(4,5),19);steel.setColorAt(0,QColor("#a5a49b"));steel.setColorAt(.4,QColor("#6e706a"));steel.setColorAt(1,QColor("#272a29"));+ p->setBrush(steel);p->drawEllipse(point,11,11);+ p->setPen(QPen(QColor("#1a1c1b"),3));p->drawLine(point+QPointF(-6,-3),point+QPointF(6,3));+ p->drawLine(point+QPointF(-3,6),point+QPointF(3,-6));+ }+}+class RingNode final : public QSGGeometryNode {public:- int capacity = 0, indexCapacity = 0, indexedSteps = -1;+ int capacity = 0, indexCapacity = 0, indexedSteps = -1, indexedDotSteps = -1;};// Small vertex buffers animate the rim without repainting or uploading a full CD-sized texture.@@ -169,10 +290,10 @@ QSGNode *ProgressRing::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)node->setMaterial(new QSGVertexColorMaterial);node->setFlag(QSGNode::OwnsMaterial);}- const qreal radius = qMin(width(), height())/2-6;- const qreal arc = 2*M_PI*m_progress;+ const qreal radius = m_linear ? 1 : qMin(width(), height())/2-6;+ const qreal arc = m_linear ? qMax(0.,width())*m_progress : 2*M_PI*m_progress;const int steps = qMax(1, int(std::ceil(radius*arc/2)));- constexpr int dotSteps = 24;+ const int dotSteps = m_linear ? 0 : 24;auto *geometry = node->geometry();geometry->setDrawingMode(QSGGeometry::DrawTriangles);const int ringVertices = (steps+1)*4;@@ -194,7 +315,7 @@ QSGNode *ProgressRing::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)#endif// Adjacent triangles share the exact same edge vertices. Their topology// changes only when the segment count changes, not as the wave animates.- if (node->indexedSteps != steps) {+ if (node->indexedSteps != steps || node->indexedDotSteps != dotSteps) {auto *indices = geometry->indexDataAsUInt();for (int i=0; i<steps; ++i) for (int band=0; band<3; ++band) {const uint a=i*4+band, b=(i+1)*4+band;@@ -202,6 +323,7 @@ QSGNode *ProgressRing::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)}for (int i=0; i<dotSteps*9; ++i) *indices++ = ringVertices+i;node->indexedSteps = steps;+ node->indexedDotSteps = dotSteps;geometry->markIndexDataDirty();}auto *vertices = geometry->vertexDataAsColoredPoint2D();@@ -222,6 +344,12 @@ QSGNode *ProgressRing::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)constexpr bool opacity[] = {false, true, true, false};auto edge = [&](qreal t) {const qreal envelope = qBound(0., qMin(t,arc-t)*radius/14, 1.);+ if (m_linear) {+ const qreal y = height()/2 + std::sin(t*2*M_PI/24-m_phase)*m_amplitude*envelope;+ std::array<QPointF,4> points;+ for (int j=0; j<4; ++j) points[j]=QPointF(t,y+offsets[j]);+ return points;+ }const qreal r = radius + std::sin(t*28-m_phase)*m_amplitude*envelope;const qreal sine = std::sin(t), cosine = -std::cos(t);std::array<QPointF,4> points;diff --git a/src/disc.h b/src/disc.hindex ac5719d..af8b14f 100644--- a/src/disc.h+++ b/src/disc.h@@ -6,12 +6,18 @@class Disc : public QQuickPaintedItem {Q_OBJECTQ_PROPERTY(bool vinyl READ vinyl WRITE setVinyl NOTIFY vinylChanged)+ Q_PROPERTY(bool cassette READ cassette WRITE setCassette NOTIFY cassetteChanged)+ Q_PROPERTY(QColor shellColor READ shellColor WRITE setShellColor NOTIFY cassetteChanged)Q_PROPERTY(QImage artwork READ artwork WRITE setArtwork NOTIFY artworkChanged)Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)Q_PROPERTY(bool overlay READ overlay WRITE setOverlay NOTIFY overlayChanged)public:explicit Disc(QQuickItem *parent = nullptr);void paint(QPainter *painter) override;+ bool cassette() const { return m_cassette; }+ void setCassette(bool v) { if(m_cassette==v)return;m_cassette=v;update();emit cassetteChanged(); }+ QColor shellColor() const { return m_shellColor; }+ void setShellColor(QColor v) { if(m_shellColor==v)return;m_shellColor=v;update();emit cassetteChanged(); }bool vinyl() const { return m_vinyl; }void setVinyl(bool value) { if(m_vinyl==value)return; m_vinyl=value; update(); emit vinylChanged(); }QImage artwork() const { return m_art; }@@ -23,6 +29,7 @@ public:static QImage fallbackArt(int size = 1000);signals:void vinylChanged();+ void cassetteChanged();void artworkChanged();void overlayChanged();void labelColorChanged();@@ -31,16 +38,22 @@ private:QColor m_labelColor;bool m_overlay = false, m_vinyl = false;void paintVinyl(QPainter *painter);+ void paintCassette(QPainter *painter);+ bool m_cassette=false;+ QColor m_shellColor=QColor("#262326");};class ProgressRing : public QQuickItem {Q_OBJECT+ Q_PROPERTY(bool linear READ linear WRITE setLinear NOTIFY changed)Q_PROPERTY(qreal progress READ progress WRITE setProgress NOTIFY changed)Q_PROPERTY(qreal phase READ phase WRITE setPhase NOTIFY changed)Q_PROPERTY(qreal amplitude READ amplitude WRITE setAmplitude NOTIFY changed)Q_PROPERTY(QColor accent READ accent WRITE setAccent NOTIFY changed)public:explicit ProgressRing(QQuickItem *parent = nullptr) : QQuickItem(parent) { setFlag(ItemHasContents); }+ bool linear() const { return m_linear; }+ void setLinear(bool value) { if (m_linear==value) return; m_linear=value; update(); emit changed(); }qreal progress() const { return m_progress; }qreal phase() const { return m_phase; }qreal amplitude() const { return m_amplitude; }@@ -54,6 +67,7 @@ signals:protected:QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override;private:+ bool m_linear=false;qreal m_progress=0, m_phase=0, m_amplitude=0;QColor m_accent;};diff --git a/src/main.cpp b/src/main.cppindex 2c0f4e5..4608281 100644--- a/src/main.cpp+++ b/src/main.cpp@@ -1,4 +1,6 @@#include "player.h"+#include "tapesound.h"+#include "vinylnoise.h"#include "library.h"#include "listening.h"#include "musicactions.h"@@ -53,6 +55,7 @@#include <QUrlQuery>#include <QWheelEvent>#include <iostream>+#include <cstring>#include <sys/resource.h>#include <unistd.h>#include <taglib/fileref.h>@@ -108,8 +111,9 @@ public:Q_INVOKABLE void shape(QWindow *window, bool queue) {if (!window) return;const bool mini = window->property("miniMode").toBool();+ const bool cassette=window->property("cassette").toBool();const int targetWidth = mini ? 300 : queue ? 860 : 530;- const int targetHeight = mini ? 354 : 730;+ const int targetHeight = mini ? (window->property("showHorizontalSeek").toBool()?382:354) : 730;window->setMinimumWidth(0);window->setMinimumHeight(0);window->setMaximumWidth(targetWidth);@@ -119,13 +123,14 @@ public:window->setMinimumHeight(targetHeight);if (mini && window->property("menuOpen").toBool()) { window->setMask(QRegion(0,0,targetWidth,targetHeight));return; }if (mini) {- QRegion region(6,6,288,288,QRegion::Ellipse);+ QRegion region=cassette?QRegion(18,60,264,176):QRegion(6,6,288,288,QRegion::Ellipse);+ if(cassette)region|=QRegion(50,240,200,26);if (window->property("backgroundBlur").toBool()) {QPainterPath backdrop; backdrop.addRoundedRect(QRectF(0,0,300,targetHeight),21,21);region=QRegion(backdrop.toFillPolygon().toPolygon());}- else region-=window->property("vinyl").toBool()?QRegion(146,146,8,8,QRegion::Ellipse):QRegion(136,136,28,28,QRegion::Ellipse);- region |= QRegion(50,268,200,84);+ else if(!cassette)region-=window->property("vinyl").toBool()?QRegion(146,146,8,8,QRegion::Ellipse):QRegion(136,136,28,28,QRegion::Ellipse);+ region |= QRegion(50,268,200,targetHeight-270);if (auto *notice=window->findChild<QQuickItem *>("actionNotice"); notice && notice->isVisible())region |= QRegion(notice->mapRectToScene(notice->boundingRect()).toAlignedRect());window->setMask(region); return;@@ -137,8 +142,9 @@ public:QPainterPath backdrop; backdrop.addRoundedRect(QRectF(0, 0, window->width(), window->height()), 21, 21);window->setMask(QRegion(backdrop.toFillPolygon().toPolygon())); return;}- QRegion region(44, 73, 442, 442, QRegion::Ellipse);- region -= window->property("vinyl").toBool()?QRegion(259,288,12,12,QRegion::Ellipse):QRegion(243,272,44,44,QRegion::Ellipse);+ QRegion region=cassette?QRegion(60,156,410,276):QRegion(44,73,442,442,QRegion::Ellipse);+ if(cassette)region|=QRegion(115,439,300,36);+ if(!cassette)region -= window->property("vinyl").toBool()?QRegion(259,288,12,12,QRegion::Ellipse):QRegion(243,272,44,44,QRegion::Ellipse);if (auto *bar = window->findChild<QQuickItem *>("sourceBar"))region |= QRegion(bar->mapRectToScene(bar->boundingRect()).toAlignedRect());if (auto *deck = window->findChild<QQuickItem *>("playerDeck"))@@ -711,14 +717,14 @@ static int exercise(Player &player, Theme &theme, Lyrics &lyrics, QQuickWindow *check(tonearm->property("lowered").toDouble()>.99,"playing lowers the tonearm onto the grooves");capture("14-tonearm-playing");player.seek(player.duration()*.85);QTest::qWait(650);- check(tonearm->property("armAngle").toDouble()>outerAngle+12,"tonearm tracks inward as song progress advances");+ check(waitFor([&]{return tonearm->property("armAngle").toDouble()>outerAngle+12;}),"tonearm tracks inward as song progress advances");capture("14-tonearm-inner");player.setMiniMode(true);QTest::qWait(450);const auto tip=shaft->mapToScene(QPointF(0,213));check(tonearm->isVisible()&&tip.x()>0&&tip.x()<300&&tip.y()>0&&tip.y()<268,"Mini tonearm stays on the record above its controls");capture("14-tonearm-mini");player.setMiniMode(false);QTest::qWait(250);player.pause();QTest::qWait(500);- check(tonearm->property("lowered").toDouble()==0&&qAbs(tonearm->property("armAngle").toDouble()+4)<.01,"pausing lifts and parks the arm");+ check(waitFor([&]{return tonearm->property("lowered").toDouble()==0&&qAbs(tonearm->property("armAngle").toDouble()+4)<.1;}),"pausing lifts and parks the arm after the spring settles");const bool motion=player.motion();player.setMotion(false);player.play();QTest::qWait(80);check(tonearm->property("lowered").toDouble()==1,"reduced motion lowers the arm without animation");player.pause();QTest::qWait(30);check(tonearm->property("lowered").toDouble()==0,"reduced motion parks the arm immediately");@@ -731,6 +737,149 @@ static int exercise(Player &player, Theme &theme, Lyrics &lyrics, QQuickWindow *check(window->property("discFlipped").toBool(),"tonearm decoration does not intercept disc gestures");window->setProperty("discFlipped",false);QTest::qWait(400);}+ {+ const int originalTrack=player.currentIndex();const auto originalPosition=player.position();+ const auto speedPosition=player.position();+ player.setVinylSpeed(33);player.play();window->setProperty("spinSpeed",200.);window->setProperty("spinAngle",0.);QTest::qWait(250);+ check(window->property("vinylDegreesPerSecond").toDouble()==200&&window->property("spinAngle").toDouble()>35&&window->property("spinAngle").toDouble()<65,"33⅓ RPM rotates the vinyl at 200 degrees per second");+ player.setVinylSpeed(45);window->setProperty("spinSpeed",270.);window->setProperty("spinAngle",0.);QTest::qWait(250);+ check(window->property("vinylDegreesPerSecond").toDouble()==270&&window->property("spinAngle").toDouble()>50&&window->property("spinAngle").toDouble()<85,"45 RPM rotates the vinyl at 270 degrees per second");+ check(player.position()-speedPosition>200&&player.position()-speedPosition<1000&&player.currentIndex()==originalTrack,"changing record RPM keeps the song advancing in real time");+ player.setVinylSpeed(0);check(window->property("vinylDegreesPerSecond").toDouble()==9,"Relaxed retains the original gentle rotation");+ player.setVinylSpeed(90);check(player.vinylSpeed()==0,"unsupported vinyl speeds are ignored");+ player.setVinylSpeed(33);player.pause();+ player.setHorizontalSeek(true);QTest::qWait(100);+ auto *seek=findItem(window->contentItem(),"horizontalSeek");auto *deck=findItem(window->contentItem(),"playerDeck");auto *queue=findItem(window->contentItem(),"queuePanel");+ check(seek&&seek->isVisible()&&deck&&queue&&deck->y()+deck->height()==queue->y()+queue->height(),"optional horizontal seeking preserves player and sidebar alignment");+ if(seek){+ QTest::mouseClick(window,Qt::LeftButton,Qt::NoModifier,seek->mapToScene(QPointF(seek->width()*.7,seek->height()/2)).toPoint());+ check(waitFor([&]{return qAbs(player.position()-player.duration()*.7)<800;}),"horizontal progress bar seeks to the selected point");+ const auto before=player.position();QTest::keyClick(window,Qt::Key_Left);+ check(waitFor([&]{return player.position()<before;}),"horizontal progress bar supports keyboard seeking");+ }+ capture("22-horizontal-vinyl");+ player.setMiniMode(true);QTest::qWait(300);auto *miniSeek=findItem(window->contentItem(),"miniHorizontalSeek");+ check(miniSeek&&miniSeek->isVisible()&&miniSeek->y()>290&&window->height()==382&&window->mask().contains(QPoint(150,310)),"Mini seek bar sits below the whole record and inside its input mask");+ if(miniSeek){QTest::mouseClick(window,Qt::LeftButton,Qt::NoModifier,miniSeek->mapToScene(QPointF(50,16)).toPoint());check(waitFor([&]{return qAbs(player.position()-player.duration()*.25)<1000;}),"Mini horizontal seeking controls the same playback");}+ capture("22-horizontal-mini");player.setMiniMode(false);player.setHorizontalSeek(false);QTest::qWait(400);+ if(auto *prefs=window->findChild<QObject*>("preferencesPopup")) {+ QMetaObject::invokeMethod(prefs,"open");QTest::qWait(200);+ click("vinylSpeed2");check(player.vinylSpeed()==45,"Preferences selects 45 RPM");click("vinylSpeed2");+ check(findItem(window->contentItem(),"vinylSpeed2")->property("checked").toBool(),"selected record speed cannot become unchecked");click("vinylSpeed1");+ capture("22-vinyl-preferences");+ for(const char *name:{"horizontalSeekToggle","vinylCrackleToggle","vinylStaticToggle","vinylSkipsToggle"}) {+ auto *option=findItem(window->contentItem(),name);if(!option){check(false,name);continue;}+ option->forceActiveFocus();QTest::qWait(100);click(name);+ check(option->property("checked").toBool(),name);click(name);+ }+ QMetaObject::invokeMethod(prefs,"close");QTest::qWait(200);+ }+ if(tonearm&&shaft){+ auto *handle=findItem(window->contentItem(),"needleHandle");+ check(handle&&handle->isEnabled(),"vinyl exposes an accessible needle handle");+ auto dragTo=[&](double angle){+ const auto from=shaft->mapToScene(QPointF(0,197)).toPoint();+ const double a=angle*M_PI/180;+ const auto to=tonearm->mapToScene(QPointF(378-210*std::sin(a),100+210*std::cos(a))).toPoint();+ QTest::mousePress(window,Qt::LeftButton,Qt::NoModifier,from);QTest::qWait(60);+ const double start=tonearm->property("dragAngle").toDouble();+ const auto heldPosition=player.position();bool tracksPointer=true;+ for(int step=1;step<=12;++step){+ const double next=start+(angle-start)*step/12;+ const double radians=next*M_PI/180;+ const auto point=tonearm->mapToScene(QPointF(378-210*std::sin(radians),100+210*std::cos(radians))).toPoint();+ QTest::mouseMove(window,point,25);QTest::qWait(10);+ tracksPointer &= tonearm->property("dragging").toBool() && qAbs(tonearm->property("armAngle").toDouble()-next)<1;+ }+ check(tracksPointer,"needle follows continuous pointer movement without coordinate feedback");+ check(qAbs(player.position()-heldPosition)<200,"drag preview does not repeatedly seek playback");+ QTest::mouseRelease(window,Qt::LeftButton,Qt::NoModifier,to);+ };+ dragTo(16);+ check(waitFor([&]{return player.playing()&&qAbs(player.position()-player.duration()*.5)<1200;}),"dropping the needle at the middle grooves seeks and starts playback");+ check(!tonearm->property("dragging").toBool(),"needle releases its pointer after a valid drop");+ QTest::qWait(600);capture("22-needle-dropped");+ const auto before=player.position();const auto from=shaft->mapToScene(QPointF(0,197)).toPoint();+ QTest::mousePress(window,Qt::LeftButton,Qt::NoModifier,from);QTest::qWait(60);QTest::keyClick(window,Qt::Key_Escape);QTest::mouseRelease(window,Qt::LeftButton,Qt::NoModifier,from);+ check(waitFor([&]{return player.playing();})&&!tonearm->property("dragging").toBool()&&qAbs(player.position()-before)<1200,"Escape cancels needle dragging and resumes without seeking");+ player.pause();QTest::qWait(650);const auto parkedPosition=player.position();dragTo(-7);QTest::qWait(100);+ check(!player.playing()&&qAbs(player.position()-parkedPosition)<200,"dropping outside the grooves parks the needle without seeking");+ player.setMiniMode(true);QTest::qWait(450);dragTo(21);+ check(waitFor([&]{return player.playing()&&qAbs(player.position()-player.duration()*.75)<1200;}),"needle dragging maps correctly in Mini mode");+ player.setMiniMode(false);player.pause();QTest::qWait(650);+ }+ player.setVinylSkips(true);player.setVinylSpeed(33);player.seek(10000);player.play();QTest::qWait(40);+ QVariant skipped;QMetaObject::invokeMethod(window,"skipGroove",Q_RETURN_ARG(QVariant,skipped));+ check(skipped.toBool()&&waitFor([&]{return player.position()>=11700&&player.position()<13000;}),"optional groove skip advances by one 33⅓ RPM revolution");+ player.pause();QMetaObject::invokeMethod(window,"skipGroove",Q_RETURN_ARG(QVariant,skipped));check(!skipped.toBool(),"groove skips never run while paused");+ player.seek(player.duration()-3000);player.play();QMetaObject::invokeMethod(window,"skipGroove",Q_RETURN_ARG(QVariant,skipped));check(!skipped.toBool(),"groove skips do not cross the end of a song");player.pause();player.setVinylSkips(false);+ VinylNoise noise(false);noise.setVolume(.5);noise.setCrackle(true);check(!noise.isOpen(),"vinyl noise keeps no stream while paused");+ noise.setActive(true);const auto pcm=noise.read(144000);qint16 peak=0;+ for(qsizetype i=0;i+1<pcm.size();i+=2){qint16 value;std::memcpy(&value,pcm.constData()+i,2);peak=qMax(peak,qint16(std::abs(int(value))));}+ check(pcm.size()==144000&&peak>100&&peak<30000,"vinyl crackle produces bounded non-silent samples without clipping");+ noise.setCrackle(false);check(!noise.isOpen(),"turning off all vinyl effects releases the stream");noise.setHiss(true);check(noise.isOpen()&&!noise.read(4800).isEmpty(),"surface hiss can run independently of crackle");noise.setVolume(0);check(!noise.isOpen(),"muting releases the vinyl effects stream");+ player.setVinylSpeed(45);player.setHorizontalSeek(true);player.setVinylCrackle(true);player.setVinylStatic(true);player.setVinylSkips(true);+ {Player restored(temp+"/player.ini");check(restored.vinylSpeed()==45&&restored.horizontalSeek()&&restored.vinylCrackle()&&restored.vinylStatic()&&restored.vinylSkips(),"vinyl speed, seek bar, and independent effects survive relaunch");}+ player.setVinylSpeed(33);player.setHorizontalSeek(false);player.setVinylCrackle(false);player.setVinylStatic(false);player.setVinylSkips(false);+ player.select(originalTrack,false);player.seek(originalPosition);QTest::qWait(200);+ }+ {+ TapeSound cue(false);int cues=0;QObject::connect(&cue,&TapeSound::triggered,&cue,[&]{++cues;});+ cue.setEnabled(true);cue.setVolume(.5);cue.observe("local","one");+ check(cues==0,"cassette sound is silent on initial playback discovery");+ cue.observe("local","two");cue.observe("local","two");cue.observe("local","three");+ check(cues==1,"cassette sound ignores duplicate metadata and coalesces rapid skipping");+ QTest::qWait(170);cue.observe("local","four");check(cues==2,"a later track change triggers a fresh cassette cue");+ cue.setEnabled(false);cue.observe("local","five");cue.setEnabled(true);cue.observe("local","five");+ check(cues==2,"disabling cassette sounds does not replay skipped cues when enabled");+ cue.setVolume(0);cue.observe("local","six");cue.setVolume(.5);cue.observe("cider","remote-one");+ check(cues==2,"muting and switching sources are silent");+ QTest::qWait(170);cue.observe("cider","remote-two");check(cues==3,"Cider track identities trigger the same transport cue");+ cue.observe("cider",{});QTest::qWait(170);cue.observe("cider","remote-three");+ check(cues==3,"reconnecting Cider does not create a false cassette cue");+ for(auto sample:{QAudioFormat::UInt8,QAudioFormat::Int16,QAudioFormat::Int32,QAudioFormat::Float}) {+ QAudioFormat format;format.setSampleRate(24000);format.setChannelCount(2);format.setSampleFormat(sample);+ const auto pcm=TapeSound::synthesize(format);+ check(pcm.size()==format.bytesForFrames(6720),"cassette cue has a bounded duration in each supported audio format");+ }+ player.setCassetteSounds(false);{Player restored(temp+"/player.ini");check(!restored.cassetteSounds(),"cassette sound preference survives relaunch");}player.setCassetteSounds(true);+ }+ const auto cassetteTrack=player.currentIndex();const auto cassettePosition=player.position();+ player.setMedium("cassette");QTest::qWait(450);+ check(window->property("cassette").toBool()&&!player.vinyl()&&player.currentIndex()==cassetteTrack&&player.position()==cassettePosition,"Cassette switches appearance without changing the selected song or position");+ {Player restored(temp+"/player.ini");check(restored.medium()=="cassette","Cassette appearance survives relaunch");}+ player.setMedium("unknown");check(player.medium()=="cassette","unknown appearance cannot replace the saved selection");+ check(!findItem(window->contentItem(),"vinylTonearm")&&window->mask().contains(QPoint(265,294))&&!window->mask().contains(QPoint(265,110)),"Cassette has its own rectangular input silhouette without a tonearm or spindle hole");+ auto *reel=findItem(window->contentItem(),"cassetteReel0");auto *cassetteSeek=findItem(window->contentItem(),"cassetteSeek");+ check(reel&&cassetteSeek&&cassetteSeek->isVisible()&&!ring->isVisible(),"Cassette exposes reels and its linear seek control");+ auto *transport=qobject_cast<TapeSound*>(qmlContext(window)->contextProperty("tapeSound").value<QObject*>());+ check(transport&&transport->enabled(),"Cassette appearance enables its optional transport sound");+ player.setCassetteSounds(false);QTest::qWait(10);check(transport&&!transport->enabled(),"Cassette sound toggle updates the audio engine");player.setCassetteSounds(true);+ capture("21-cassette-front");+ if(reel) {+ player.seek(player.duration()*.45);+ player.play();QTest::qWait(300);const auto angle=reel->rotation();QTest::qWait(300);+ check(reel->rotation()!=angle&&findItem(window->contentItem(),"discFace")->rotation()==0,"playing rotates the cassette reels while the artwork label stays still");+ auto *wave=findItem(window->contentItem(),"cassetteSeekWave");+ check(wave&&wave->property("linear").toBool()&&wave->property("amplitude").toDouble()>2,"cassette playback uses the shared animated squiggly progress track");+ capture("21-cassette-playing");+ player.setMotion(false);QTest::qWait(100);const auto still=reel->rotation();QTest::qWait(200);+ check(reel->rotation()==still,"reduced motion freezes cassette reels");player.setMotion(true);player.pause();QTest::qWait(60);const auto stopped=reel->rotation();QTest::qWait(160);+ check(reel->rotation()==stopped,"cassette transport stops its reels when paused");+ check(wave&&qFuzzyIsNull(wave->property("amplitude").toDouble()),"cassette progress wave settles when paused");+ }+ QTest::mouseClick(window,Qt::LeftButton,Qt::NoModifier,QPoint(340,457));+ check(waitFor([&]{return qAbs(player.position()-player.duration()*.75)<1000;}),"cassette seek bar scrubs the same player");+ const auto beforeCassetteKey=player.position();QTest::keyClick(window,Qt::Key_Right);+ check(waitFor([&]{return player.position()>beforeCassetteKey;}),"cassette seek bar remains keyboard accessible");+ window->setProperty("discFlipped",true);QTest::qWait(500);+ check(findItem(window->contentItem(),"albumTrackList")->y()<200&&findItem(window->contentItem(),"discBackFooter")->y()<335,"cassette reverse aligns album content inside its shell");capture("21-cassette-back");+ player.setMiniMode(true);QTest::qWait(450);capture("21-cassette-mini-back");+ window->setProperty("discFlipped",false);QTest::qWait(450);capture("21-cassette-mini");+ check(window->mask().contains(QPoint(150,150))&&findItem(window->contentItem(),"miniControls")->y()>265,"Mini cassette keeps its full shell visible above playback controls");+ player.setMiniMode(false);player.seek(cassettePosition);player.setVinyl(true);QTest::qWait(400);+ check(!findItem(window->contentItem(),"cassetteReel0")&&player.vinyl(),"switching back to Vinyl releases cassette reels");+ check(transport&&!transport->enabled(),"Vinyl appearance disables cassette transport sounds");capture("11-vinyl-front");QTest::mouseMove(window,QPoint(265,185)); QTest::qWait(100);QTest::mouseDClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(265,185));@@ -1128,6 +1277,8 @@ int main(int argc, char **argv) {MusicActions musicActions(&cider);Listening listening(&cider);DiscPresentation presentation;+ TapeSound tapeSound(!test);+ VinylNoise vinylNoise(!test);Native native;const qint64 backendReady = startup.elapsed();if (!test) registerMpris(&player);@@ -1142,6 +1293,8 @@ int main(int argc, char **argv) {engine.rootContext()->setContextProperty("native", &native);engine.rootContext()->setContextProperty("lyrics", &lyrics);engine.rootContext()->setContextProperty("presentation", &presentation);+ engine.rootContext()->setContextProperty("tapeSound", &tapeSound);+ engine.rootContext()->setContextProperty("vinylNoise", &vinylNoise);engine.rootContext()->setContextProperty("cider", &cider);engine.rootContext()->setContextProperty("library", &library);engine.rootContext()->setContextProperty("musicActions", &musicActions);diff --git a/src/player.cpp b/src/player.cppindex 4080c85..0949073 100644--- a/src/player.cpp+++ b/src/player.cpp@@ -37,7 +37,15 @@ Player::Player(const QString &settingsPath, QObject *parent)m_shuffle = m_settings.value("shuffle", false).toBool();m_repeat = qBound(0, m_settings.value("repeat", 0).toInt(), 2);m_light = m_settings.value("light", false).toBool();- m_vinyl = m_settings.value("vinyl", false).toBool();+ m_medium=m_settings.value("medium",m_settings.value("vinyl",false).toBool()?"vinyl":"cd").toString();+ if(!QStringList{"cd","vinyl","cassette"}.contains(m_medium))m_medium="cd";+ m_vinylSpeed=m_settings.value("vinylSpeed",33).toInt();+ if(m_vinylSpeed!=0&&m_vinylSpeed!=33&&m_vinylSpeed!=45)m_vinylSpeed=33;+ m_horizontalSeek=m_settings.value("horizontalSeek",false).toBool();+ m_vinylCrackle=m_settings.value("vinylCrackle",false).toBool();+ m_vinylStatic=m_settings.value("vinylStatic",false).toBool();+ m_vinylSkips=m_settings.value("vinylSkips",false).toBool();+ m_cassetteSounds = m_settings.value("cassetteSounds", true).toBool();m_motion = m_settings.value("motion", true).toBool();m_ciderAutoStart = m_settings.value("ciderAutoStart", false).toBool();m_miniOnTop = m_settings.value("miniOnTop", false).toBool();@@ -360,7 +368,17 @@ void Player::move(int from, int to) {void Player::setMiniOnTop(bool value) { if (m_miniOnTop == value) return; m_miniOnTop = value; emit miniOnTopChanged(); save(); }void Player::setMiniMode(bool value) { if (m_miniMode == value) return; m_miniMode = value; emit miniModeChanged(); save(); }void Player::setBackgroundBlur(bool value) { if (m_backgroundBlur == value) return; m_backgroundBlur = value; emit backgroundBlurChanged(); save(); }-void Player::setVinyl(bool value) { if (m_vinyl==value) return; m_vinyl=value; emit vinylChanged(); save(); }+void Player::setVinyl(bool value) { setMedium(value?"vinyl":"cd"); }+void Player::setMedium(const QString &value) {+ if(m_medium==value || !QStringList{"cd","vinyl","cassette"}.contains(value))return;+ const bool wasVinyl=vinyl();m_medium=value;emit mediumChanged();if(wasVinyl!=vinyl())emit vinylChanged();save();+}+void Player::setVinylSpeed(int value) { if((value!=0&&value!=33&&value!=45)||value==m_vinylSpeed)return;m_vinylSpeed=value;emit settingsChanged();save(); }+void Player::setHorizontalSeek(bool value) { if(value==m_horizontalSeek)return;m_horizontalSeek=value;emit settingsChanged();save(); }+void Player::setVinylCrackle(bool value) { if(value==m_vinylCrackle)return;m_vinylCrackle=value;emit settingsChanged();save(); }+void Player::setVinylStatic(bool value) { if(value==m_vinylStatic)return;m_vinylStatic=value;emit settingsChanged();save(); }+void Player::setVinylSkips(bool value) { if(value==m_vinylSkips)return;m_vinylSkips=value;emit settingsChanged();save(); }+void Player::setCassetteSounds(bool enabled) { if(m_cassetteSounds==enabled)return;m_cassetteSounds=enabled;emit settingsChanged();save(); }void Player::setMotion(bool value) { m_motion = value; emit settingsChanged(); save(); }void Player::fail(const QString &message) { m_error = message; emit errorChanged(); }void Player::dismissError() { m_error.clear(); emit errorChanged(); }@@ -369,8 +387,15 @@ void Player::save() {m_settings.setValue("shuffle", m_shuffle);m_settings.setValue("repeat", m_repeat);m_settings.setValue("light", m_light);- m_settings.setValue("vinyl", m_vinyl);+ m_settings.setValue("vinyl", vinyl());+ m_settings.setValue("medium", m_medium);m_settings.setValue("motion", m_motion);+ m_settings.setValue("cassetteSounds", m_cassetteSounds);+ m_settings.setValue("vinylSpeed",m_vinylSpeed);+ m_settings.setValue("horizontalSeek",m_horizontalSeek);+ m_settings.setValue("vinylCrackle",m_vinylCrackle);+ m_settings.setValue("vinylStatic",m_vinylStatic);+ m_settings.setValue("vinylSkips",m_vinylSkips);m_settings.setValue("backgroundBlur", m_backgroundBlur);m_settings.setValue("miniMode", m_miniMode);m_settings.setValue("miniOnTop", m_miniOnTop);diff --git a/src/player.h b/src/player.hindex c0a565a..1237e01 100644--- a/src/player.h+++ b/src/player.h@@ -21,6 +21,13 @@ struct LoadedArtwork { QImage image; QString file; bool created = false; };class Player : public QObject {Q_OBJECT+ Q_PROPERTY(QString trackKey READ trackKey NOTIFY trackChanged)+ Q_PROPERTY(int vinylSpeed READ vinylSpeed WRITE setVinylSpeed NOTIFY settingsChanged)+ Q_PROPERTY(bool horizontalSeek READ horizontalSeek WRITE setHorizontalSeek NOTIFY settingsChanged)+ Q_PROPERTY(bool vinylCrackle READ vinylCrackle WRITE setVinylCrackle NOTIFY settingsChanged)+ Q_PROPERTY(bool vinylStatic READ vinylStatic WRITE setVinylStatic NOTIFY settingsChanged)+ Q_PROPERTY(bool vinylSkips READ vinylSkips WRITE setVinylSkips NOTIFY settingsChanged)+ Q_PROPERTY(bool cassetteSounds READ cassetteSounds WRITE setCassetteSounds NOTIFY settingsChanged)Q_PROPERTY(QString title READ title NOTIFY trackChanged)Q_PROPERTY(QString artist READ artist NOTIFY trackChanged)Q_PROPERTY(QString album READ album NOTIFY trackChanged)@@ -40,6 +47,7 @@ class Player : public QObject {Q_PROPERTY(int repeatMode READ repeatMode WRITE setRepeatMode NOTIFY settingsChanged)Q_PROPERTY(bool light READ light WRITE setLight NOTIFY settingsChanged)Q_PROPERTY(bool vinyl READ vinyl WRITE setVinyl NOTIFY vinylChanged)+ Q_PROPERTY(QString medium READ medium WRITE setMedium NOTIFY mediumChanged)Q_PROPERTY(bool motion READ motion WRITE setMotion NOTIFY settingsChanged)Q_PROPERTY(bool ciderAutoStart READ ciderAutoStart WRITE setCiderAutoStart NOTIFY settingsChanged)Q_PROPERTY(bool miniOnTop READ miniOnTop WRITE setMiniOnTop NOTIFY miniOnTopChanged)@@ -50,6 +58,19 @@ class Player : public QObject {public:explicit Player(const QString &settingsPath, QObject *parent = nullptr);~Player() override;+ QString trackKey() const { return currentUrl().toString(); }+ int vinylSpeed() const { return m_vinylSpeed; }+ bool horizontalSeek() const { return m_horizontalSeek; }+ bool vinylCrackle() const { return m_vinylCrackle; }+ bool vinylStatic() const { return m_vinylStatic; }+ bool vinylSkips() const { return m_vinylSkips; }+ void setVinylSpeed(int value);+ void setHorizontalSeek(bool value);+ void setVinylCrackle(bool value);+ void setVinylStatic(bool value);+ void setVinylSkips(bool value);+ bool cassetteSounds() const { return m_cassetteSounds; }+ void setCassetteSounds(bool enabled);QString title() const;QString artist() const;QString album() const;@@ -69,7 +90,9 @@ public:bool shuffle() const { return m_shuffle; }int repeatMode() const { return m_repeat; }bool light() const { return m_light; }- bool vinyl() const { return m_vinyl; }+ bool vinyl() const { return m_medium=="vinyl"; }+ QString medium() const { return m_medium; }+ void setMedium(const QString &value);void setVinyl(bool value);bool motion() const { return m_motion; }bool ciderAutoStart() const { return m_ciderAutoStart; }@@ -110,6 +133,7 @@ public:static Track readTrack(const QString &path);signals:void vinylChanged();+ void mediumChanged();void discDetailsChanged();void trackChanged();void artworkChanged();@@ -146,7 +170,10 @@ private:QSet<QString> m_shuffleVisited;QString m_artFile, m_error;bool m_ciderAutoStart = false;- bool m_vinyl = false;+ int m_vinylSpeed=33;+ bool m_horizontalSeek=false, m_vinylCrackle=false, m_vinylStatic=false, m_vinylSkips=false;+ bool m_cassetteSounds=true;+ QString m_medium = "cd";bool m_shuffle = false, m_light = false, m_motion = true, m_busy = false, m_backgroundBlur = false, m_miniMode = false, m_miniOnTop = false;int m_repeat = 0;qint64 m_restorePosition = -1;diff --git a/src/tapesound.cpp b/src/tapesound.cppnew file mode 100644index 0000000..686861c--- /dev/null+++ b/src/tapesound.cpp@@ -0,0 +1,81 @@+#include "tapesound.h"+#include <QAudioSink>+#include <QAudioDevice>+#include <QMediaDevices>+#include <cmath>+#include <cstring>++TapeSound::TapeSound(bool outputEnabled,QObject *parent):QObject(parent),m_outputEnabled(outputEnabled) {}+TapeSound::~TapeSound() { stop(); }+void TapeSound::setEnabled(bool enabled) {+ if(m_enabled==enabled)return;+ m_enabled=enabled;if(!enabled)stop();emit changed();+}+void TapeSound::setVolume(qreal volume) {+ volume=qBound(0.,volume,1.);if(m_volume==volume)return;+ m_volume=volume;+ if(volume==0)stop();else if(m_sink)m_sink->setVolume(volume*.45);+ emit changed();+}+void TapeSound::observe(const QString &source,const QString &key) {+ const bool transition=!key.isEmpty()&&!m_key.isEmpty()&&source==m_source&&key!=m_key;+ m_source=source;m_key=key;+ if(!transition || !m_enabled || m_volume<=0 || (m_lastCue.isValid()&&m_lastCue.elapsed()<160))return;+ m_lastCue.restart();emit triggered();+ if(m_outputEnabled)play();+}+QByteArray TapeSound::synthesize(const QAudioFormat &format) {+ if(!format.isValid() || format.sampleRate()>192000 || format.channelCount()>8)return {};+ const int frames=qRound(format.sampleRate()*.28);+ QByteArray pcm(format.bytesForFrames(frames),Qt::Uninitialized);+ quint32 random=0x43a55e7u;double low=0;+ for(int i=0;i<frames;++i) {+ const double t=double(i)/format.sampleRate();+ random^=random<<13;random^=random>>17;random^=random<<5;+ const double noise=double(random)/2147483648.-1.;+ low+=.24*(noise-low);+ double sample=0;+ for(int hit=0;hit<3;++hit) {+ const double dt=t-(hit==0?.008:hit==1?.061:.132);+ if(dt<0)continue;+ const double strength=hit==0?.64:hit==1?.17:.43;+ // Latch impact, brief spring chatter, then the softer engaging key.+ const double attack=1-std::exp(-dt*4500);+ sample+=strength*attack*(low*2.2*std::exp(-dt*115)+ +(noise-low)*.45*std::exp(-dt*330)+ +std::sin(dt*(hit==2?180:125)*6.283185307)*.45*std::exp(-dt*92));+ }+ sample=qBound(-.85,sample,.85);+ // A short final fade guarantees a quiet endpoint with every sample rate.+ sample*=qBound(0.,(.28-t)/.025,1.);+ for(int channel=0;channel<format.channelCount();++channel) {+ char *out=pcm.data()+(i*format.channelCount()+channel)*format.bytesPerSample();+ switch(format.sampleFormat()) {+ case QAudioFormat::UInt8: *out=char(qRound((sample+1)*127.5));break;+ case QAudioFormat::Int16: {const qint16 value=qRound(sample*32767);std::memcpy(out,&value,2);break;}+ case QAudioFormat::Int32: {const qint32 value=qint32(sample*2147483647.);std::memcpy(out,&value,4);break;}+ case QAudioFormat::Float: {const float value=float(sample);std::memcpy(out,&value,4);break;}+ default:return {};+ }+ }+ }+ return pcm;+}+void TapeSound::stop() {+ if(m_sink) {auto *sink=m_sink.data();m_sink=nullptr;sink->disconnect(this);sink->stop();sink->deleteLater();}+ m_buffer.close();+}+void TapeSound::play() {+ stop();+ const auto device=QMediaDevices::defaultAudioOutput();if(device.isNull())return;+ QAudioFormat format;format.setSampleRate(24000);format.setChannelCount(1);format.setSampleFormat(QAudioFormat::Int16);+ if(!device.isFormatSupported(format))format=device.preferredFormat();+ if(m_format!=format || m_buffer.data().isEmpty()){m_format=format;m_buffer.setData(synthesize(format));}+ if(m_buffer.data().isEmpty() || !m_buffer.open(QIODevice::ReadOnly))return;+ auto *sink=new QAudioSink(device,format,this);m_sink=sink;sink->setVolume(m_volume*.45);+ connect(sink,&QAudioSink::stateChanged,this,[this,sink](QAudio::State state){+ if(m_sink==sink&&(state==QAudio::IdleState||(state==QAudio::StoppedState&&sink->error()!=QAudio::NoError)))+ QMetaObject::invokeMethod(this,[this,sink]{if(m_sink==sink)stop();},Qt::QueuedConnection);+ });+ sink->start(&m_buffer);+}diff --git a/src/tapesound.h b/src/tapesound.hnew file mode 100644index 0000000..a0fc507--- /dev/null+++ b/src/tapesound.h@@ -0,0 +1,36 @@+#pragma once+#include <QObject>+#include <QAudioFormat>+#include <QBuffer>+#include <QElapsedTimer>+#include <QPointer>+class QAudioSink;++// A short, synthesized transport cue; no samples or persistent audio stream.+class TapeSound : public QObject {+ Q_OBJECT+ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY changed)+ Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY changed)+public:+ explicit TapeSound(bool outputEnabled=true, QObject *parent=nullptr);+ ~TapeSound() override;+ bool enabled() const { return m_enabled; }+ qreal volume() const { return m_volume; }+ void setEnabled(bool enabled);+ void setVolume(qreal volume);+ Q_INVOKABLE void observe(const QString &source, const QString &key);+ static QByteArray synthesize(const QAudioFormat &format);+signals:+ void changed();+ void triggered();+private:+ void play();+ void stop();+ bool m_enabled=false, m_outputEnabled=true;+ qreal m_volume=0;+ QString m_source, m_key;+ QElapsedTimer m_lastCue;+ QPointer<QAudioSink> m_sink;+ QBuffer m_buffer;+ QAudioFormat m_format;+};diff --git a/src/vinylnoise.cpp b/src/vinylnoise.cppnew file mode 100644index 0000000..56778ba--- /dev/null+++ b/src/vinylnoise.cpp@@ -0,0 +1,60 @@+#include "vinylnoise.h"+#include <QAudioSink>+#include <QAudioDevice>+#include <QMediaDevices>+#include <cmath>+#include <cstring>+VinylNoise::VinylNoise(bool outputEnabled,QObject *parent):QIODevice(parent),m_outputEnabled(outputEnabled) {}+VinylNoise::~VinylNoise() { stop(); }+void VinylNoise::setActive(bool v){if(m_active==v)return;m_active=v;updateOutput();emit changed();}+void VinylNoise::setCrackle(bool v){if(m_crackle==v)return;m_crackle=v;updateOutput();emit changed();}+void VinylNoise::setHiss(bool v){if(m_hiss==v)return;m_hiss=v;updateOutput();emit changed();}+void VinylNoise::setVolume(qreal v){v=qBound(0.,v,1.);if(m_volume==v)return;m_volume=v;updateOutput();emit changed();}+void VinylNoise::stop(){+ if(m_sink){auto *sink=m_sink.data();m_sink=nullptr;sink->disconnect(this);sink->stop();sink->deleteLater();}+ close();+}+void VinylNoise::updateOutput(){+ if(!m_active||(!m_crackle&&!m_hiss)||m_volume<=0){stop();return;}+ if(isOpen()){if(m_sink)m_sink->setVolume(m_volume*.35);return;}+ m_format.setSampleRate(24000);m_format.setChannelCount(1);m_format.setSampleFormat(QAudioFormat::Int16);+ const auto device=m_outputEnabled?QMediaDevices::defaultAudioOutput():QAudioDevice{};+ if(m_outputEnabled){+ if(device.isNull())return;+ if(!device.isFormatSupported(m_format))m_format=device.preferredFormat();+ }+ if(!m_format.isValid())return;+ m_pop=m_low=m_fade=0;open(QIODevice::ReadOnly);+ if(!m_outputEnabled)return;+ auto *sink=new QAudioSink(device,m_format,this);m_sink=sink;sink->setVolume(m_volume*.35);+ connect(sink,&QAudioSink::stateChanged,this,[this,sink](QAudio::State state){+ if(m_sink==sink&&state==QAudio::StoppedState&&sink->error()!=QAudio::NoError)+ QMetaObject::invokeMethod(this,[this,sink]{if(m_sink==sink)stop();},Qt::QueuedConnection);+ });+ sink->start(this);+}+qint64 VinylNoise::readData(char *data,qint64 length){+ const int frameBytes=m_format.bytesPerFrame();if(frameBytes<=0)return 0;+ const qint64 frames=length/frameBytes;const int rate=m_format.sampleRate();+ const bool crackle=m_crackle.load(),hiss=m_hiss.load();+ const double decay=std::exp(-1./(rate*.0008));+ for(qint64 i=0;i<frames;++i){+ m_random^=m_random<<13;m_random^=m_random>>17;m_random^=m_random<<5;+ const double white=double(m_random)/2147483648.-1.;+ m_low+=.025*(white-m_low);+ if(crackle&&m_random%quint32(qMax(1,rate/5))==0)m_pop=.25+.45*std::abs(white);+ m_pop*=decay;m_fade=qMin(1.,m_fade+1./(rate*.04));+ const double value=qBound(-.8,((crackle?m_pop*white:0)+(hiss?white*.012+m_low*.035:0))*m_fade,.8);+ for(int channel=0;channel<m_format.channelCount();++channel){+ char *out=data+i*frameBytes+channel*m_format.bytesPerSample();+ switch(m_format.sampleFormat()){+ case QAudioFormat::UInt8:*out=char(qRound((value+1)*127.5));break;+ case QAudioFormat::Int16:{const qint16 v=qRound(value*32767);std::memcpy(out,&v,2);break;}+ case QAudioFormat::Int32:{const qint32 v=qint32(value*2147483647.);std::memcpy(out,&v,4);break;}+ case QAudioFormat::Float:{const float v=float(value);std::memcpy(out,&v,4);break;}+ default:return 0;+ }+ }+ }+ return frames*frameBytes;+}diff --git a/src/vinylnoise.h b/src/vinylnoise.hnew file mode 100644index 0000000..d8c8f80--- /dev/null+++ b/src/vinylnoise.h@@ -0,0 +1,42 @@+#pragma once+#include <QIODevice>+#include <QAudioFormat>+#include <QPointer>+#include <atomic>+class QAudioSink;++class VinylNoise : public QIODevice {+ Q_OBJECT+ Q_PROPERTY(bool active READ active WRITE setActive NOTIFY changed)+ Q_PROPERTY(bool crackle READ crackle WRITE setCrackle NOTIFY changed)+ Q_PROPERTY(bool hiss READ hiss WRITE setHiss NOTIFY changed)+ Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY changed)+public:+ explicit VinylNoise(bool outputEnabled=true,QObject *parent=nullptr);+ ~VinylNoise() override;+ bool active() const { return m_active; }+ bool crackle() const { return m_crackle; }+ bool hiss() const { return m_hiss; }+ qreal volume() const { return m_volume; }+ void setActive(bool value);+ void setCrackle(bool value);+ void setHiss(bool value);+ void setVolume(qreal value);+ bool isSequential() const override { return true; }+ qint64 bytesAvailable() const override { return isOpen()?4096+QIODevice::bytesAvailable():0; }+signals:+ void changed();+protected:+ qint64 readData(char *data,qint64 length) override;+ qint64 writeData(const char *,qint64) override { return -1; }+private:+ void updateOutput();+ void stop();+ bool m_outputEnabled, m_active=false;+ std::atomic<bool> m_crackle{false}, m_hiss{false};+ qreal m_volume=0;+ QAudioFormat m_format;+ QPointer<QAudioSink> m_sink;+ quint32 m_random=0x41a399u;+ double m_pop=0,m_low=0,m_fade=0;+};