Formation rates of core-collapse supernovae and gamma-ray bursts