Asian military technology was not a simple progression curve where possessing firearms = instant win. Armies based on infantry and gunpowder in the 16th/17th Century were still pretty weak in the face of the mass-cavalry formations that the nomads of Central Asia/Mongolia used (a point brought up by Mughal commanders looking at European pike-and-shot formations).
A swarm of horse archers during this period still had greater range and versatility than any infantry formation of the time, no matter how well-drilled - and this was shown quite clearly in the repeated Manchu victories over the largest gunpowder army in the world, the Ming army. Sure, the pre-Conquest Manchus also adopted cannon but that was more for attacking fortified cities rather than for field use. In any case, the Chinese tradition of appointing bureaucrats into military posts could hardly have helped their military efficiency, no matter how advanced their armies were.
As for modernization... the sclerotic and intensely-factionalized Ming court was just not capable of creating any grand plan to fix the dynasty by this point, much less look towards the future. And as for why it didn't happen by itself amongst the Ming populace... that itself is a much larger debate on why 'China didn't modernize'.