My general comment is that the number of days a visitor needs/wants in a city is massively affected by what she wants to do there. Just walking around (part of) the historic area can be accomplished in a few hours. Attractions like the castle in Edinburgh and the Gaudi sites in Barcelona take time--often about 2 hours, though I'd guess the castle takes longer. Museums (art or history) can be all-day affairs in some cases. So without more information about you, I don't know whether your time allocations are right for you--which is the only thing that matters.
I don't find Madrid a terribly exciting/interesting city. To me, 4 days would make sense only if you were into art and wanted to spend a lot of time in the 3 major museums (and even then, 4 days might be one day too long) OR if you wanted to take some of the really good day-trips popular from Madrid; Toledo, Segovia, and Cuenca are the side-trips I consider the best (though I haven't been to El Escorial). If you haven't much interest in art, you might consider spending a couple of nights in Toledo.
Barcelona has lots to see--much of it requiring prepurchased, timed, tickets. It also has day-trip possibilities if you find you want a change of scene. My favorite would be Girona, but it is sight-rich and would benefit from an overnight stay. I haven't been to Montserrat.
There's a lot of flying (or ferrying) in your itinerary for just 2 days in Dublin (which I haven't seen) and Edinburgh. I find dealing with airports a real joy-killer and would certainly not try to hit both Ireland and Scotland within 4 days. Scotland aficionados will tell you that it's a shame to go there and see only Edinburgh, nice city though it is. I expect the same can be said about Dublin, if not moreso.
Few, if any, people on this forum have ever suggested staying in Brussels, which is widely considered a not-very-interesting city. I don't know; I haven't been there.