"Then Moses sang" (Exodus 15:1). This is what Scripture says: "I waited and waited for the LORD" (Psalms 40:2). Rabbi Pinchas the Priest said in the name of Rabbi Chama: If you have hoped and it has not come, hope again. David said, "Hope in the LORD; be strong and let your heart take courage, and hope in the LORD" (Psalms 27:14) - if your hope has come, well and good; and if not, hope again. David said, "I waited and waited for the LORD" (Psalms 40:2), "and He brought me up out of the pit of tumult, out of the miry clay" (Psalms 40:3) - out of the clay of bricks; "and He set my feet upon a rock" - for He gave me the spoil of Egypt and the spoil of the sea; "He established my steps and put a new song in my mouth" (Psalms 40:3-4). "Then Moses sang." What is the meaning of "then"? The Holy One, blessed be He, made the dry land into a sea for the generation of Enosh, as it is said, "then it was begun to call upon the name of the LORD" (Genesis 4:26). And for us He made the sea into dry land; with "then" we praise Him.
Then Moses Sang and the Reward of Hoping Again for the LORD
Yalkut Shimoni on Torah 241:2
(שמות טו א) אָז יָשִׁיר מֹשֶׁה. זֶה שֶׁאָמַר הַכָּתוּב (תהלים מ, ב) "קַוֹּה קִוִּיתִי ה'", אָמַר רַבִּי פִּנְחָס הַכֹּהֵן בְּשֵׁם רַבִּי חָמָא, אִם קִוִּיתָ וְלֹא בָּא חֲזֹר וְקַוֵּה, אָמַר דָּוִד "קַוֵּה אֶל ה' חֲזַק וְיַאֲמֵץ לִבֶּךָ וְקַוֵּה אֶל ה'", אִם בָּא קִוּוּיְךָ, יָפֶה, וְאִם לָאו, חֲזֹר וְקַוֵּה, אָמַר דָּוִד (שם מ, ב ד) "קַוֹּה קִוִּיתִי ה'" "וַיַּעֲלֵנִי מִבּוֹר שָׁאוֹן מִטִּיט הַיָּוֵן", מִטִּיט לְבֵנִים, "וַיָּקֶם עַל סֶלַע רַגְלַי", שֶׁנָּתַן לִי בִּזַּת מִצְרַיִם וּבִזַּת הַיָּם. "כּוֹנֵן אֲשֻׁרָי וַיִּתֵּן בְּפִי שִׁיר חָדָשׁ". אָז יָשִׁיר מֹשֶׁה. מַהוּ אָז, עָשָׂה הַקָּדוֹשׁ בָּרוּךְ הוּא לְדוֹרוֹ שֶׁל אֱנוֹשׁ הַיַּבָּשָׁה יָם, שֶׁנֶּאֱמַר (בראשית ד, כו) "אָז הוּחַל לִקְרֹא בְּשֵׁם ה'". וְלָנוּ עָשָׂה הַיָּם יַבָּשָׁה, בְּאָז אָנוּ מְקַלְּסִין אוֹתוֹ.