The court determines custody and visitation based on what is in the best interests of the child. The only takes the parents into consideration as a facet of that over-arching paradigm. But, newborns offer a unique challenge. This post will go over infants and the legal issues they present.
Ideally, you would work out your parental duties and custody issues before the child is born. But once that agreement reaches the court, there are evidentiary issues the court must overcome. Typically, the court relies on a child's history to determine what is in their best interest. The court can judge what is best based on their schooling, medical records, sports activities, and social circles.
Unfortunately, newborns have none of those characteristics, therefore, courts are forced to rely on anecdotal guesses based upon the parents' representations.
Fathers only gain custody rights once paternity is established. Paternity can be presumed or proven in court and with evidence. The parents can stipulate as to paternity but, unless you were married when the child was born, you would have to submit it to the court for approval.
If the other parent is uncooperative with the paternity issue, then you may have to wait until the child is born. It is possible to get a prenatal DNA test done however that requires the cooperation of the mother.
If you are trying to obtain custody rights over your newborn child, you may want to speak to a family law attorney. A lawyer can go over the facts with you and determine the best way to obtain your parental rights. Sometimes it means you have to go to court, but sometimes you can work it out on your own. A lawyer can work with you and your ex-spouse to try and come to an equitable solution.