I agree with just about everyone trying to give you advice here. Nothing more needs to be said on that end.
It is time to take a hard look at yourself, particularly at what is going on in your head. This is not said to be mean, only to be helpful from someone who has been there.
I think if you try to trace back your mental process here you will find at its core some level of insecurity. Because I don't think that a guy who is super secure would tolerate this type of situation for a day. He would know that he deserved a more high quality girl and that he would find one eventually. At least one better than this current one.
Because you have this insecurity, when even a low-quality girl shows interest in you, it has a profoundly positive effect on your sense of self. She is validating you in a way that you cannot internally. Whether it be from your choice of profession, your living situation, or because of a rough time growing up...whatever it may be, something is missing inside of you. And that something is genuine confidence and self-worth. Again, otherwise you would walk away from this situation with very little hesitation.
So... when this girl's actions now take AWAY this validating feeling, you feel worse than before when it started. And nobody likes to feel bad. So what happens? A thread like this. Where you are scrambling, hoping, for some sort of explanation, some sort of understanding as to what the **** just happened.
I'll take a shot in the dark at what really happened. You are dealing with a very mixed-up girl. She does like you to some extent. She probably thinks your a great guy. But she knew that she didn't deserve you. So she kept up her side fling with the ex because as bad as he might be, she knows that her ex is someone that is on her level. Destructive people cling to each other in ****ed-up relationships that are far worse than what the AFC can imagine. The mutual violence, cheating, lying, etc only bring them closer together in a twisted co-dependent way.
Confronted with this situation, or some idea that something was amiss between you two, instead of walking away, you tried to save it. She's NOT WORTH saving. And SHE KNOWS this. But that won't stop her from trying to have her cake (you) and eat it too (the ex).
Again, its time to take a look at yourself. Its time to stop trying to prove yourself to women like this, and time to make them prove themselves to you.