  We show that the meromorphic Jacobi form that counts the quarter-BPS states
in N=4 string theories can be canonically decomposed as a sum of a mock Jacobi
form and an Appell-Lerch sum. The quantum degeneracies of single-centered black
holes are Fourier coefficients of this mock Jacobi form, while the Appell-Lerch
sum captures the degeneracies of multi-centered black holes which decay upon
wall-crossing. The completion of the mock Jacobi form restores the modular
symmetries expected from $AdS_3/CFT_2$ holography but has a holomorphic anomaly
reflecting the non-compactness of the microscopic CFT. For every positive
integral value m of the magnetic charge invariant of the black hole, our
analysis leads to a special mock Jacobi form of weight two and index m, which
we characterize uniquely up to a Jacobi cusp form. This family of special forms
and another closely related family of weight-one forms contain almost all the
known mock modular forms including the mock theta functions of Ramanujan, the
generating function of Hurwitz-Kronecker class numbers, the mock modular forms
appearing in the Mathieu and Umbral moonshine, as well as an infinite number of
new examples.
