# `TuningFork.Pattern.Ahead`
[🔗](https://github.com/jaman/tuning_fork/blob/v0.1.11/tuning_fork/lib/tuning_fork/pattern/ahead.ex#L1)

A `TuningFork.Pattern.Player` rendered ahead of time in a process of its own, so the
stage takes its chunks ready-made and the pattern's synthesis runs on another core.

    {:ok, ahead} = TuningFork.Pattern.Ahead.start_link(player: player, chunk: 256, channels: 2)
    pcm = TuningFork.Pattern.Ahead.next(ahead)
    TuningFork.Pattern.Ahead.apply(ahead, &TuningFork.Pattern.Player.gain(&1, 0.5))

Up to `:depth` chunks are kept rendered (default 8); `next/1` returns the oldest and
renders one on the spot when none is ready. A change made with `apply/2` reaches the
player at the render frontier, at most `:depth` chunks ahead of what `next/1` has
handed out.

# `apply`

```elixir
@spec apply(GenServer.server(), (TuningFork.Pattern.Player.t() -&gt;
                             TuningFork.Pattern.Player.t())) :: :ok
```

Change the player with `fun` from the render frontier on.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `cycle`

```elixir
@spec cycle(GenServer.server()) :: float()
```

Where the player has reached at the render frontier, in cycles.

# `next`

```elixir
@spec next(GenServer.server()) :: binary()
```

The next chunk.

# `rendered`

```elixir
@spec rendered(GenServer.server()) :: non_neg_integer()
```

How many chunks are rendered and waiting.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Start rendering `:player` in chunks of `:chunk` frames for `:channels` channels, `:depth` chunks ahead.

# `stop`

```elixir
@spec stop(GenServer.server()) :: :ok
```

Stop rendering.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
