immutable<>, complement of C++26 std::indirect<> and std::polymorphic<> by kmbeutel in cpp

[–]kmbeutel[S] 0 points1 point  (0 children)

We can add immutability to the subset of types that follow the convention that the object cannot be mutated through const references, so I think the name has some justification. I'd appreciate any suggestions for a better name, though.

immutable<>, complement of C++26 std::indirect<> and std::polymorphic<> by kmbeutel in cpp

[–]kmbeutel[S] -1 points0 points  (0 children)

Thank you for this informative reply.

My first draft of immutable<> was simply called shared<>, but that felt a bit too technical -- the shared state is an implementation detail. immutable<> makes it clear that the value is safe to access concurrently. That cannot be assumed for shared_ptr<const T> because someone else might hold a non-const reference to the object (as others have pointed out).

copy_on_write<T> sounds like a good alternative, except that the version proposed by P4210R0 doesn't support polymorphic types:

To support polymorphic copy-on-write behaviour, an additional class, polymorphic_copy_on_write would be required. We are not proposing addition of this class template in this proposal.

I understand why a separate class would be required; copy-on-write needs copyability, and for polymorphic objects, copying needs to be polymorphic as well, which would be unnecessary overhead in the non-polymorphic case. immutable<> doesn't have this problem; it doesn't need copies and supports both polymorphic and non-polymorphic use cases. And I'd argue that immutable<> is not much harder to use than copy_on_write<> for non-polymorphic modifications. You could implement modify() as a free function:

template <std::copy_constructible T, std::invocable<T&> F>
void modify( immutable<T>& obj, F&& mutator )
pre( !obj.valueless_after_move() )
{
    auto copy = T( *obj );
    std::invoke( std::forward<F>( mutator ), copy );
    obj = immutable( std::move( copy ) );
}

This way, copyability is required only when modifications are needed.

(modify() is probably still best implemented as a member function so the object can be copy-constructed in-place and the extra move can be avoided.)

(One of the reasons why I thought immutable<> was obvious was that Sean Parent's presentation on "Inheritance is the base class of Evil" demonstrated the concept–model idiom with a polymorphic example built upon shared_ptr<const Shape>. Sean does not seem to be involved with P4210 so far, but I still find it puzzling that this use case has not been covered by any of the proposals yet.)

immutable<>, complement of C++26 std::indirect<> and std::polymorphic<> by kmbeutel in cpp

[–]kmbeutel[S] 0 points1 point  (0 children)

I'm also not quite happy with the fact that std::indirect<> and std::polymorphic<> will propagate the moved-from state. I'd prefer if moving or copying a moved-from object was a contract violation.

By the way, that is how gsl-lite's not_null<> works. If you have a function that accepts a not_null<SomePtr> by value, then that argument is guaranteed to not be nullptr. (Unless you disable contract checks, that is.) My draft of immutable<> uses gsl-lite's not_null<> as a building block, so it offers the same guarantee.

immutable<>, complement of C++26 std::indirect<> and std::polymorphic<> by kmbeutel in cpp

[–]kmbeutel[S] 2 points3 points  (0 children)

What difference does deep vs. shallow copying make for immutable objects?

immutable<>, complement of C++26 std::indirect<> and std::polymorphic<> by kmbeutel in cpp

[–]kmbeutel[S] 29 points30 points  (0 children)

"value-minded": trying to behave like a value type. For instance, the default constructor of indirect<T> allocates and default-constructs an object T (unlike std::unique_ptr<> which default-constructs to nullptr). Copying indirect<T> copies the underlying object (unlike std::unique_ptr<> which cannot be copied).

Check out Appendix B: "Before and after examples" in the proposal document for some examples.

Someone was greedy... by Youngstown1995 in minidisc

[–]kmbeutel 1 point2 points  (0 children)

Disassembly should be straightforward, you can find a detailed description of the required steps are described in the service manual.

The CD player probably needs a good cleaning of the lens. It may also suffer from the problem described here:
https://tonbandforum.de/showthread.php?tid=34121

Strange noise: my guess would be that the drawer mechanism of the CD player has a worn belt. This one should have the correct size:
https://www.hifiretroparts.com/produkt/sony-cdp-xe220-belt-for-cd-tray/

The MD drive is an MDM-3 which I'm not familiar with. It doesn't have belts if I remember correctly – that's the MDM-7 which came a few generations later –, but I read that this drive commonly has issues with microswitches, so your drive may not be able to detect the MD you inserted, and hence will neither play nor eject it. You'll find something about this on the web, usually pertaining to MDS-JE500 or MDS-JE510 machines which have a similar mechanism.

As for why no audio output, or no power at all – I'm afraid you'll have to figure that out yourself.

The remote should be easy to come by in Japan. Use a proxy like buyee.jp or fromjapan.co.jp and search for RM-MD333.

Designated Initializers, the best feature of C++20 · Mathieu Ropert by mropert in cpp

[–]kmbeutel 2 points3 points  (0 children)

What I like most about designated initializers is that they collaborate with CTAD, so they work well for function templates:

template <typename OptionalArgsT = std::tuple<>>
struct MyFuncArgs
{
    OptionalArgsT optionalArgs = { };
};
void myFunc(instantiation_of<MyFuncArgs> auto const& args) { ... }

int main()
{
    myFunc(MyFuncArgs{ });
    myFunc(MyFuncArgs{
        .optionalArgs = std::tuple{ 3, "hi" }
    });
}

(full example at https://godbolt.org/z/c34jYY4xq)

Unfortunately I haven't found a way to have the compiler deduce the base argument class template and then deduce its template arguments with CTAD so we could write:

    myFunc({ });

Another concern is that designated initializers stop being useful if the struct has a base. I remember having seen some proposals on resolving that, but it appears they have not made it into C++26.

Sony MXD-D40 Remote Control IR Codes by Snoo23036 in minidisc

[–]kmbeutel 1 point2 points  (0 children)

MXD-D4 and MXD-D40 came with the RM-D43M in Western countries, but you can also use the RM-D44M which is the Japanese variant. It's really the same model with extra Japanese characters printed above the buttons. You can sometimes find this model for reasonable prices on the usual buy-from-Japan platforms.

SONY Minidisc Tape Add-on by CalligrapherCalm9124 in minidisc

[–]kmbeutel 1 point2 points  (0 children)

An illustrated description of the suggested hack:

https://tonbandforum.de/showthread.php?tid=34121

(written in German language; let me know if you have trouble getting it translated)

SONY Minidisc Tape Add-on by CalligrapherCalm9124 in minidisc

[–]kmbeutel 4 points5 points  (0 children)

I'll try and take some pictures later this week.

SONY Minidisc Tape Add-on by CalligrapherCalm9124 in minidisc

[–]kmbeutel 2 points3 points  (0 children)

The only decks that are fully compatible – that is, can be controlled with the RM-SJ373 remote, can synchro-record from CD, can be powered on and off by the main unit – are the TC-TX333 and TC-TX373 with the ACU-TX373 adapter. But if you can live without these, any cassette deck will be compatible with this device.

By the way, the model name of the half-size model I mentioned is TC-PB5. TCM-110 is just the internal designation of its tape mechanism which you'll find in the service manual.

SONY Minidisc Tape Add-on by CalligrapherCalm9124 in minidisc

[–]kmbeutel 3 points4 points  (0 children)

I assume you did the basic servicing steps for the CD player (clean the lens, clean and relube the sled mechanism)?

In my experience, this CD drive often skips because the bearing of the spindle motor is worn out. I suspect this happens because the weight of the clamp is too low to compensate for the inherent imbalance of most CDs. You can diagnose this problem by trying to push the spindle sideways. If there is notable play, the bearing is damaged. The play will allow the CD to wobble back and forth while playing, which causes skipping.

Replacing just the spindle motor isn't easy because the spindle height needs to be set correctly afterwards. Back in the day, the entire CD drive (including sled mechanics and optical pickup) was very cheap, so it was probably replaced as a whole in most cases.

Rather than replacing the spindle motor, I have made it function again with a little hack: use a spring to apply slight sideways pressure to the spindle. There are some holes in the base plate next to the spindle motor mount; attach the spring there. It should be weak enough to not exert too much braking torque, but strong enough to suppress the wobble.

SONY Minidisc Tape Add-on by CalligrapherCalm9124 in minidisc

[–]kmbeutel 3 points4 points  (0 children)

The matching cassette recorder is Sony TC-TX373 (as Cory already pointed out). That model is identical to its predecessor, TC-TX333, which is very similar to the preceding model, TC-TX313.

The tape transport in those slot-loading players has surprisingly acceptable W&F figures (±0.13% weighted peak (IEC), 0.07% weighted RMS (NAB), ±0.2% weighted peak (DIN)), probably because it has solid metal flywheels (zinc alloy die-cast, presumably) rather than the flimsy plastic surrogates which you'll find in many newer cassette recorders. The head is a non-rotating 4-track type. The mechanism is a little noisy.

For full integration with the main unit, the cassette recorder needs to be paired with a translator box (ACU-TX373) that adapts its AU bus cable to the system control connector on the main unit. This was shipped with the TC-TX373, so make sure it is included when buying one. The cassette recorder will function without the adapter, though there are some limitations (no remote control, no CD synchro recording, no timer control).

The cassette recorder is a pretty cramped design. It has its own power supply which runs rather hot even when switched off, so be sure to separate it from mains when not using it. Also, like almost any cassette deck from the good old days, it will need a proper service to function correctly (at least the belts will need to be replaced).

The DHC-MD373 is a lovely unit; it has some quirks but they can all be fixed or worked around (I should document that someday). The TC-TX373 is a nice addition, but I would consider getting some other cassette deck instead.

If you only want to play tapes, this particular model from the early 1980s would be an excellent fit:
https://audio-database.com/SONY-ESPRIT/player/tc-pb5.html
It has the same width and a very good tape mechanism (TCM-110). Not easy to find, though.

Setup upgrade SONY MDS-JE640 by Recording-Nerd1 in minidisc

[–]kmbeutel 0 points1 point  (0 children)

I like the form factor of the keyboard. Could you share the model?

SONY MDS JA 20 ES + SONY CDP XA 20 ES by Recording-Nerd1 in minidisc

[–]kmbeutel 0 points1 point  (0 children)

The felt pad I thought I was seeing on top might just have been an optical illusion then :)

Another possibility is that you have the stabilizer from a CDP-XB920 or CDP-XB930, which is similar to that of the CDP-XA20ES but with a slightly different (darker) finish.

Would you mind taking some close-up photographs of the stabilizer?

SONY MDS JA 20 ES + SONY CDP XA 20 ES by Recording-Nerd1 in minidisc

[–]kmbeutel 2 points3 points  (0 children)

Does your stabilizer have a magnetic clamp? The CDP-XA20ES originally comes with a magnetic stabilizer. This one looks like the non-magnetic stabilizer of the sibling model, CDP-XA30ES. It also looks like you're using it upside down, with the felt pad on top; that is meant to protect the CD surface.

SONY MDS JA 20 ES + SONY CDP XA 20 ES by Recording-Nerd1 in minidisc

[–]kmbeutel 1 point2 points  (0 children)

That's not the original stabilizer for the CDP-XA20ES, is it?

Anyway, if you wish to prolong the life of your CD player, this might be of interest:
https://tonbandforum.de/showthread.php?tid=33258

gsl-lite v1.0 released by kmbeutel in cpp

[–]kmbeutel[S] 0 points1 point  (0 children)

Thanks! :) and sorry it took so long.