from typing import Optional


def get_accidental_index(accidental: Optional[str]) -> int:
    """Returns the index of accidental string, e.g. #->1."""
    if not accidental or type(accidental) != str:
        return 0
    if not all(x in "#bx" for x in accidental):
        raise ValueError(f"Error in accidental {accidental}.")
    flat = accidental.count("b")
    sharp = accidental.count("#")
    double_sharp = accidental.count("x")
    return sharp + double_sharp * 2 - flat