Unfortunately, if you ask a police officer "Am I free to leave?" He may well refuse to answer, or try to deflect your question. The problem is that police and prosecutors "want it both ways." If they question you and you say something incriminating, then they want to claim that you were not in custody and it was a "consensual encounter." On the other hand, if you don't say anything incriminating or try to leave, they want to be free to charge you with "resisting" or "disorderly." There really are no 'bright line' rules on when someone is/isn't in custody (the courts use terms like "totality of the circumstances"), but most of the time the state (police and prosecutors) will prevail in having the situation called what they wish.
Arresting someone like this (for "disorderly" or "resisting") where there is not an underlying charge, is often a case of "complaint insurance." If the officer thinks a person will complain, they will arrest them and charge them, so if/when a complaint does come they can protest that the person was simply a complaining law-breaker. The charge is BS and dropped quickly by the prosecutor, but the police will still use it to try and tar the complainer.
I routinely represent people on these "BS" resisting charges. The prosecutor won't touch them, and if the officer insists on going forward I just request the taser logs and records and the case disappears in a puff of smoke. The police don't want to release those records. But the police really don't care. They figured "I tasered the M**F** and he spent a night in jail. That'll teach him." What makes it really frustrating is that the vast majority of these cases come from a few problem officers, whom their fellow officers will complain about -- but never on the record.
Contrary to what at least some police seem to think, people in this country still have some "rights" and simply because a cop barks an order doesn't mean that people are legally obligate to jump to comply, let alone get arrested/tased if they don't. What is really scary is the number of people who seem to think that unthinking compliance is a virtue. Many people say "you should just always do what the police say" and "the Cop is always right." Such people are not law-abiding, they are law-ignorant.