I have studied the quantum harmonic oscillator and solved the Schrodinger equation to find the eigen-energies given by
$$ E_n = \left(n+\frac{1}{2}\right)\hbar \omega. $$
Which means the energy levels are separated by
$$ \Delta E = \hbar \omega = hf $$
I have also studied blackbody radiation and one of the assumptions Planck made was that the energy levels accessible to the cavity oscillators are separated by this same amount $\Delta E$. This makes sense to me as the source of blackbody radiation is just an oscillator in the wall so I can see the connection between a quantum harmonic oscillator and a cavity oscillator. However a photon that is emitted when an electron transitions between energy levels in an atom is not due to any oscillators, is it just a coincidence that the energy of a non-blackbody photon is given by $ E = \hbar \omega $ or is there some connection between photons and oscillators?