NetMD.Commands (NetMD v0.1.0)

Copy Markdown View Source

High-level operations composed from NetMD.Interface commands, ported from netmd-js's netmd-commands.

Divergence from the reference: the title-space estimation (remaining_characters_for_titles/2 and friends) computes group ranges cleanly where the reference's JavaScript accidentally splices "false" and "null" strings into its worst-case length estimates.

Summary

Functions

TOC cells needed for a track's titles, as {half_width, full_width}.

Compile raw disc title strings with group markup from a NetMD.Disc, fitting as many groups as the TOC allows.

Current device state: disc presence, operating state, track and time.

Download a track to the disc: prepare, run a secure session, transfer, and release the device.

Full disc listing: title, capacity, groups and per-track details.

Get the device ready for downloads: wait until it is idle, clear any stale secure session and take control.

Characters still available for titling, as {half_width, full_width}.

Rename the disc, preserving any group markup in the raw title.

Write a disc's group structure back to the TOC.

Convert an {hours, minutes, seconds, frames} tuple to frames (512 per second).

Upload a track from the disc (MZ-RH1 only), returning the disc format and the audio prefixed with a playable header: AEA for SP, WAV with the ATRAC3 format tag for LP2/LP4.

Types

error()

@type error() :: NetMD.Interface.error()

Functions

cells_for_title(track)

@spec cells_for_title(NetMD.Disc.Track.t()) :: {non_neg_integer(), non_neg_integer()}

TOC cells needed for a track's titles, as {half_width, full_width}.

compile_disc_titles(disc)

@spec compile_disc_titles(NetMD.Disc.t()) :: {String.t(), String.t()}

Compile raw disc title strings with group markup from a NetMD.Disc, fitting as many groups as the TOC allows.

device_status(device)

@spec device_status(NetMD.Device.t()) ::
  {:ok,
   %{
     disc_present: boolean(),
     state: atom(),
     track: non_neg_integer() | nil,
     time: %{minute: integer(), second: integer(), frame: integer()} | nil
   }}
  | error()

Current device state: disc presence, operating state, track and time.

download(device, track, opts \\ [])

@spec download(NetMD.Device.t(), NetMD.Track.t(), keyword()) ::
  {:ok, %{track: non_neg_integer(), uuid: binary(), ccid: binary()}} | error()

Download a track to the disc: prepare, run a secure session, transfer, and release the device.

Options: :progress, :settle_ms (see NetMD.Interface.send_track/8), :disc_format (see NetMD.Session.download_track/3) and :attempts (see prepare_download/2).

list_content(device)

@spec list_content(NetMD.Device.t()) :: {:ok, NetMD.Disc.t()} | error()

Full disc listing: title, capacity, groups and per-track details.

prepare_download(device, opts \\ [])

@spec prepare_download(
  NetMD.Device.t(),
  keyword()
) :: :ok | error()

Get the device ready for downloads: wait until it is idle, clear any stale secure session and take control.

remaining_characters_for_titles(disc, opts \\ [])

@spec remaining_characters_for_titles(
  NetMD.Disc.t(),
  keyword()
) :: {non_neg_integer(), non_neg_integer()}

Characters still available for titling, as {half_width, full_width}.

rename_disc(device, new_name, opts \\ [])

@spec rename_disc(NetMD.Device.t(), String.t(), keyword()) :: :ok | error()

Rename the disc, preserving any group markup in the raw title.

Accepts full_width_title: to also set the full-width title.

rewrite_disc_groups(device, disc)

@spec rewrite_disc_groups(NetMD.Device.t(), NetMD.Disc.t()) :: :ok | error()

Write a disc's group structure back to the TOC.

time_to_frames(arg)

@spec time_to_frames({integer(), integer(), integer(), integer()}) :: integer()

Convert an {hours, minutes, seconds, frames} tuple to frames (512 per second).

upload(device, track, opts \\ [])

@spec upload(NetMD.Device.t(), non_neg_integer(), keyword()) ::
  {:ok, %{format: byte(), data: binary()}} | error()

Upload a track from the disc (MZ-RH1 only), returning the disc format and the audio prefixed with a playable header: AEA for SP, WAV with the ATRAC3 format tag for LP2/LP4.

Options are passed to NetMD.Interface.save_track_to_binary/3.