Unless the right is waived or is denied by this chapter, an affidavit for change of a judge or magistrate may be filed in any action pending in the court whether originating therein or pending upon appeal from an inferior court or tribunal to the circuit court. No affidavit for such change may be filed in a criminal action prior to the completion of the preliminary hearing or waiver thereof or in any proceeding for contempt committed in the presence of the court.
SDCL 15-12-21