How to calculate maximum Roth IRA contribution after maximizing solo 401k contribution

I want to maximize my contributions to both my (pre-tax) individual 401k account and my regular Roth IRA (i.e. not the Roth part of my individual 401k).
I am not sure about how to calculate my earned income for the purposes of maximizing my Roth Ira account.

Is my earned income (for Roth Ira purposes) equal to my net profit minus my individual 401k contribution minus 1/2 SE tax? 

So for example, with a net profit of 48K and a maximum individual 401k contribution of about 39,920 (employee and employer parts) and 1/2 SE tax of about $3,391, I would have an earned income of about $4,689 and this would be the maximum amount I could contribute to a regular Roth IRA?

Therefore I could not contribute the maximum $8K (i'm over 50) even though my net profit minus 1/2 of SE tax is much higher than 8K?

Thanks in advance