In every Country, city and town there is good and band, even in some village communities. Often people only see the good or the bad, it depends on your lifestyle.
Many, due to wealth, are fortunate to live in areas which are fairly safe and secure, maybe even on a gated development.
When in a foreign country, I usually take a cab trip and ask to be driven through the areas I would not want to be in, just to get a balance and see what the other side is like.
The shooting, tragic as it is, but it has got a way of life and don’t try and say that this never happens in Spain.